﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using ZHDJ.AppInterface.Models;
using ZHDJ.Core.Util;
using ZHDJ.Core;
using ZHDJ.JoinParty.BLL;
using ZHDJ.Data.BLL;
using System.Text.RegularExpressions;

namespace ZHDJ.AppInterface
{
    public class InterfaceHelper
    {
        static DataTable dtMenu = new DataTable();
        static DataTable dtNewMenu = new DataTable();
        static int layer = 0;

        #region 根据查询条件获取个人用户信息
        public static DataSet GetMembersByFilter(string filter)
        {
            string sql = "select * from tblpartyorgmember";

            sql += " where " + filter;
            return ZHDJ.Data.MySqlHelper.ExecuteDataSet(sql);
        }
        #endregion

        #region 登陆密码是否正确
        /// <summary>
        /// 登陆密码是否正确
        /// </summary> 
        /// <param name="loginID">用户登陆名</param>
        /// <param name="password">密码</param> 
        /// <returns></returns>
        public static bool PasswordIsCorrect(string loginID, string password)
        {
            string sql = " select Password from tblpartyorgmember where LoginID='" + loginID + "'";
            object obj = Data.MySqlHelper.ExecuteScalar(sql);

            if (obj == null)
                return false;

            if (ZHDJ.Core.Util.PasswordUtil.ComparePasswords(obj.ToString(), password))
                return true;
            else
                return false;
        }
        #endregion

        #region MyRegion
        public static DataSet GetMembersLoginInfo(string loginID)
        {
            string sql = string.Format(@"select Birthday, JoinPartyDate, LoginID as user_id, userno as user_name, UserName as user_truename, om.BranchID as branch_id, 
        (case runSate when '-1' then '2' else '1' end) as user_type ,
        (select IFNULL(SUM(Score),0) from tblPartyObjectScore where objecttype = 'Member' 
        and ObjectID=om.LoginID and category='PartyOnlineTest' and ScoreDate=now()) as is_can_test,
        '' as party_url,'' as person_url,'' as join_url
        from tblpartyorgmember om where LoginID='{0}'", loginID);

            return Data.MySqlHelper.ExecuteDataSet(sql);
        }
        #endregion

        #region 获取个人信息
        /// <summary>
        /// 获取个人信息
        /// </summary>
        /// <param name="loginID">登录ID</param>
        /// <returns></returns>
        public static PartyOrgMember GetPartyBuildingUserModel(string LoginID)
        {
            DataTable dt = new DataTable();
            PartyOrgMember model = new PartyOrgMember();
            string sql = @" select me.*,branch.BranchName,fi.Url from tblpartyorgmember AS me
                            LEFT JOIN tblpartyfile as fi 
                            ON me.ImageUrl=fi.ID
                            LEFT JOIN tblpartyorgbranch AS branch
                            ON me.BranchID=branch.BranchID
                            WHERE me.LoginID=@LoginID ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="LoginID",Value=LoginID}
            };
            dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];

            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.UserId = dr["LoginID"].ToString();
                model.UserName = dr["UserNo"].ToString();
                model.UserPwd = dr["Password"].ToString();
                model.UserTrueName = dr["UserName"].ToString();
                model.UserBranchId = dr["BranchID"].ToString();
                model.UserBranchName = dr["BranchName"].ToString();
                //model.UserScore = dr["UserScore"].ToString();
                model.IsPartyWorkers = Convert.ToBoolean(dr["IsPartyWorker"]);
                model.ImageUrl = dr["Url"].ToString();
                model.Gender = dr["Gender"].ToString();
                model.IdentityCard = dr["IdentityCard"].ToString();
                model.Birthday = Convert.ToString(dr["Birthday"]) == "" ? DateTime.Now : Convert.ToDateTime(dr["Birthday"]);
                model.myPoints = SumMemberintegral("Member", LoginID);
                model.myRank = GetRankingByObjectID("Member", LoginID, dr["BranchID"].ToString());
                model.MobileNo = dr["MobileNo"].ToString();
                model.Nation = dr["Nation"].ToString();
                model.PoliticsLineament = dr["PoliticsLineament"].ToString();
                model.WorkUnit = dr["WorkUnit"].ToString();
                model.MemberCostTime = GetMemberCostDate(LoginID);
                model.NativePlace = dr["NativePlace"].ToString();
                model.Educational = dr["Educational"].ToString();
                model.Email = dr["Email"].ToString();
                model.QQNumber = dr["QQNumber"].ToString();
                model.WeiXinNo = dr["WeiXinNo"].ToString();
                //model.ModifyTimeEx = Convert.ToString(dr["ModifyTimeEx"]) == "" ? DateTime.Now : Convert.ToDateTime(dr["ModifyTimeEx"]);
                model.Address = dr["Address"].ToString();
                model.WorkAddress = dr["WorkAddress"].ToString();
                model.runSate = dr["runSate"].ToString();
            }
            return model;
        }
        #endregion

        #region 根据条件获取个人信息
        /// <summary>
        /// 根据条件获取个人信息
        /// </summary>
        /// <param name="Where">Where</param>
        /// <returns></returns>
        public static DataTable GetPartyBuildingUserModelByWhere(string where)
        {
            DataTable dt = new DataTable();
            StringBuilder sb = new StringBuilder();
            sb.Append(@" select me.*,branch.BranchName,fi.Url from tblpartyorgmember AS me
                            LEFT JOIN tblpartyfile as fi 
                            ON me.ImageUrl=fi.ID
                            LEFT JOIN tblpartyorgbranch AS branch
                            ON me.BranchID=branch.BranchID ");

            if (!string.IsNullOrWhiteSpace(where))
                sb.Append(where);

            return Data.MySqlHelper.ExecuteDataSet(sb.ToString()).Tables[0];
        }
        #endregion

        #region 修改姓名
        /// <summary>
        /// 修改姓名
        /// </summary>
        /// <param name="LoginID"></param>
        /// <param name="UserName">真实姓名</param>
        /// <returns></returns>
        public static string UpdateUserNameByLoginID(string LoginID, string UserName)
        {
            string userName = string.Empty;
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="LoginID",Value=LoginID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="UserName",Value=UserName}
            };
            string sql = @" update tblpartyorgmember set UserName=@UserName where LoginID=@LoginID ";
            int i = Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
            if (i > 0)
                userName = UserName;
            return userName;
        }
        #endregion

        #region 修改性别
        /// <summary>
        /// 修改性别
        /// </summary>
        /// <param name="LoginID"></param>
        /// <param name="Gender">性别</param>
        /// <returns></returns>
        public static string UpdateGenderByLoginID(string LoginID, string Gender)
        {
            string gender = string.Empty;
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="LoginID",Value=LoginID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Gender",Value=Gender}
            };
            string sql = @" update tblpartyorgmember set Gender=@Gender where LoginID=@LoginID ";
            int i = Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
            if (i > 0)
                gender = Gender;
            return gender;
        }
        #endregion

        #region 修改生日
        /// <summary>
        /// 修改生日
        /// </summary>
        /// <param name="LoginID"></param>
        /// <param name="Birthday">出生年月日</param>
        /// <returns></returns>
        public static string UpdateBirthdayByLoginID(string LoginID, string Birthday)
        {
            string birthday = string.Empty;
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="LoginID",Value=LoginID},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="Birthday",Value=Birthday}
            };
            string sql = @" update tblpartyorgmember set Birthday=@Birthday where LoginID=@LoginID ";
            int i = Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
            if (i > 0)
                birthday = Birthday;
            return birthday;
        }
        #endregion

        #region 修改个人信息
        public static int UpdatePartyBuildingUserModel(PartyOrgMember model)
        {
            string sql = @" UPDATE `tblpartyorgmember` 
                            SET `ModifyTimeEx`=@ModifyTimeEx, `BranchID`=@BranchID,`Gender`=@Gender,`IdentityCard`=@IdentityCard,`Birthday`=@Birthday, 
                                `Nation`=@Nation, `NativePlace`=@NativePlace, `Educational`=@Educational, `MobileNo`=@MobileNo, `Email`=@Email, 
                                `QQNumber`=@QQNumber, `WeiXinNo`=@WeiXinNo, `Address`=@Address, `WorkUnit`=@WorkUnit, `WorkAddress`=@WorkAddress
                            WHERE LoginID=@LoginID ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="ModifyTimeEx",Value=model.ModifyTimeEx },
                new MySqlParameter() { DbType=DbType.String,ParameterName="BranchID",Value=model.BranchID },
                new MySqlParameter() { DbType = DbType.String, ParameterName = "Gender", Value = model.Gender },
                new MySqlParameter() { DbType=DbType.String,ParameterName="IdentityCard",Value=model.IdentityCard },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="Birthday",Value=model.Birthday },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Nation",Value=model.Nation },
                new MySqlParameter() { DbType=DbType.String,ParameterName="NativePlace",Value=model.NativePlace },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Educational",Value=model.Educational },
                new MySqlParameter() { DbType=DbType.String,ParameterName="MobileNo",Value=model.MobileNo },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Email",Value=model.Email },
                new MySqlParameter() { DbType=DbType.String,ParameterName="QQNumber",Value=model.QQNumber },
                new MySqlParameter() { DbType=DbType.String,ParameterName="WeiXinNo",Value=model.WeiXinNo },
                new MySqlParameter() { DbType = DbType.String, ParameterName = "Address", Value = model.Address },
                new MySqlParameter() { DbType=DbType.String,ParameterName="WorkUnit",Value=model.WorkUnit },
                new MySqlParameter() { DbType=DbType.String,ParameterName="WorkAddress",Value=model.WorkAddress },
                new MySqlParameter() { DbType=DbType.String,ParameterName="LoginID",Value=model.UserId }
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 获取文章数据
        /// <summary>
        /// 获取文章数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="module"></param>
        /// <param name="category"></param>
        /// <param name="searchKey"></param>
        /// <param name="banchId"></param>
        /// <returns></returns>
        public static DataSet GetPartyArticleGridData(int pageIndex, int pageSize, string module, string category, string searchKey, string banchId)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter()
                {
                    DbType = DbType.Int32,
                    ParameterName = "Begin",
                    Value = (pageIndex)*pageSize
                },
                new MySqlParameter()
                {
                    DbType = DbType.Int32,
                    ParameterName = "PageSize",
                    Value = pageSize
                }
            };
            StringBuilder sb = new StringBuilder();

            sb.Append(@" select SQL_CALC_FOUND_ROWS
article.ID, article.Title, ou.BranchName, article.ArticlesLable, article.Author,article.Content,article.CreateTime,file.Url as ImageUrl,
article.Flags as Flags,
CASE article.Flags WHEN 0 THEN '无' WHEN 1 THEN '置顶' WHEN 2 THEN '固顶' WHEN 3 THEN '置顶+固顶' END AS FlagsEx,
case article.Category WHEN NULL then article.Module WHEN '' THEN article.Module else article.Category END as Category , 
article.`Status`,
CASE article.`Status` WHEN 1 THEN '草稿'  WHEN 4 THEN '发布' END as StatusEx,
article.Module
from tblpartyarticle article
LEFT JOIN  tblpartyorgbranch ou on article.BranchID = ou.BranchID
LEFT JOIN  tblpartyfile AS file ON article.ImageID=file.ID
where 1 = 1");

            if (!string.IsNullOrEmpty(module))
            {
                sb.Append(" and Module=?Module");
                parameters.Add(new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "Module",
                    Value = module
                });
            }
            if (!string.IsNullOrEmpty(category))
            {
                sb.Append(" and Category=?Category");
                parameters.Add(new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "Category",
                    Value = category
                });
            }
            if (!string.IsNullOrEmpty(searchKey))
            {
                sb.Append(" and article.Title like ?Title ");
                parameters.Add(
                    new MySqlParameter()
                    {
                        DbType = DbType.String,
                        ParameterName = "Title",
                        Value = string.Format("%{0}%", searchKey)
                    });
            }
            if (!string.IsNullOrEmpty(banchId))
            {
                sb.Append(" and article.BranchID in (select childbranchid from tblpartyorgbranchrelation t where t.BranchID=?BranchID)");
                parameters.Add(
                    new MySqlParameter()
                    {
                        DbType = DbType.String,
                        ParameterName = "BranchID",
                        Value = banchId
                    });
            }

            sb.Append(" order by article.Status desc, article.CreateTime desc,article.Status desc limit ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            ZHDJ.Core.Log.Log4netHelper.WriteLog(sb.ToString() + module + category);
            return Data.MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray());
        }
        #endregion

        #region 获取菜单
        /// <summary>
        /// 获取菜单
        /// </summary>
        /// <param name="id">菜单ID</param>
        /// <param name="IsChild">是否有子菜单</param>
        /// <returns></returns>
        public static DataTable GetMenu(string id, bool IsChild)
        {
            dtMenu = null;
            dtNewMenu = null;
            string sql = @" select * from tblportalmovemenu where ParentID=@ParentID ORDER BY OrderNo; ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.String,ParameterName = "ParentID",Value = id}
            };
            dtMenu = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            dtNewMenu = CommonUtils.CopyDataTable(dtMenu);

            if (IsChild)
            {
                for (int i = 0; i < dtMenu.Rows.Count; i++)
                {
                    DataRow dr = dtMenu.Rows[i];
                    GetAllChildMenu(dr["id"].ToString());
                }
            }

            return dtNewMenu;
        }
        #endregion

        #region 是否有子菜单
        public static bool IsHaveChildMenu(string id)
        {
            bool result = false;
            string sql = @" select * from tblportalmovemenu where ParentID=@ParentID ORDER BY OrderNo; ";

            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.String,ParameterName = "ParentID",Value = id}
            };
            DataTable dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
                result = true;
            else
                result = false;

            return result;
        }
        #endregion

        #region 获取所有子菜单
        /// <summary>
        /// 获取所有子菜单
        /// </summary>
        /// <param name="id">菜单ID</param>
        /// <returns></returns>
        public static DataTable GetAllChildMenu(string id)
        {
            string sql = @" select * from tblportalmovemenu where ParentID=@ParentID ORDER BY OrderNo; ";

            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.String,ParameterName = "ParentID",Value = id}
            };
            DataTable dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];

            //把子菜单追加到DataTable下方
            foreach (DataRow itemChild in dt.Rows)
            {
                DataRow newRow;
                newRow = dtNewMenu.NewRow();
                newRow["ID"] = itemChild["ID"];
                newRow["Name"] = itemChild["Name"];
                newRow["NavigateUrl"] = itemChild["NavigateUrl"];
                newRow["Remark"] = itemChild["Remark"];
                newRow["OrderNo"] = itemChild["OrderNo"];
                newRow["ParentID"] = itemChild["ParentID"];
                newRow["Category"] = itemChild["Category"];
                newRow["Module"] = itemChild["Module"];
                dtNewMenu.Rows.Add(newRow);

                bool b = IsHaveChildMenu(itemChild["id"].ToString());
                if (b)
                    GetAllChildMenu(itemChild["id"].ToString());
            }
            return dt;
        }
        #endregion

        #region 获取单个文章数据
        public static PartyArticle GetPartyArticleModel(string id)
        {
            DataTable dt = new DataTable();
            PartyArticle model = new PartyArticle();

            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "ID",
                    Value = id
                }
            };
            string sql = @" SELECT article.ID,	article.Title,	article.Subhead,	article.ArticlesLable,	article.Content,	article.Summary,	article.BranchID,	
article.Module, article.Category, article.SourceId, article.Author, article.AuthorUrl, article.Status, article.Aduits,
article.ImageID, article.Flags, article.ActivityBeginTime, article.ActivityEndTime, article.CreateTime, article.CreateBy,
article.ModifyTime, article.ModifyBy, file.Url as ImageUrl FROM tblpartyarticle article
LEFT JOIN  tblpartyfile AS file ON article.ImageID = file.ID WHERE article.ID=@ID ";
            dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];

            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.Title = dr["Title"].ToString();
                model.Subhead = dr["Subhead"].ToString();
                model.ArticlesLable = dr["ArticlesLable"].ToString();
                model.Content = NoHTML(dr["Content"].ToString());
                model.Summary = dr["Summary"].ToString();
                model.BranchID = dr["BranchID"].ToString();
                model.Module = dr["Module"].ToString();
                model.Category = dr["Category"].ToString();
                model.SourceId = dr["SourceId"].ToString();
                model.Author = dr["Author"].ToString();
                model.AuthorUrl = dr["AuthorUrl"].ToString();
                model.Status = Convert.ToInt32(dr["Status"]);
                //model.Aduits = Convert.ToInt32(dr["Aduits"]);
                model.ImageID = dr["ImageID"].ToString();
                model.Flags = Convert.ToInt32(dr["Flags"]);
                //model.ActivityBeginTime = Convert.ToDateTime(dr["ActivityBeginTime"]);
                //model.ActivityEndTime = Convert.ToDateTime(dr["ActivityEndTime"]);
                //model.Views = Convert.ToInt32(dr["Views"]);
                model.ImageUrl = dr["ImageUrl"].ToString();
                model.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
            }

            return model;
        }
        #endregion

        #region 获取门户文章轮播图片
        /// <summary>
        /// 获取门户文章轮播图片
        /// </summary>
        /// <returns></returns>
        public static DataTable GetPortalArticleImage()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@" SELECT article.ID,	article.Title,	article.Subhead,	article.ArticlesLable,	article.Content,	article.Summary,	article.BranchID,	
article.Module, article.Category, article.SourceId, article.Author, article.AuthorUrl, article.Status, article.Aduits,
article.ImageID, article.Flags, article.ActivityBeginTime, article.ActivityEndTime, article.CreateTime, article.CreateBy,
article.ModifyTime, article.ModifyBy, file.Url as ImageUrl
from tblpartyarticle article
LEFT JOIN  tblpartyfile AS file ON article.ImageID = file.ID
WHERE Module = 'InformationNewsletter' AND `Status`= 4 AND(ImageID <> NULL or ImageID <> '') ORDER BY Flags DESC, CreateTime DESC LIMIT 0, 5 ");
            return Data.MySqlHelper.ExecuteDataTable(sb.ToString());
        }
        #endregion

        #region 上传头像
        /// <summary>
        /// 上传头像
        /// </summary>
        /// <param name="image">Base64字符编码图片</param>
        /// <param name="Extension">扩展名</param>
        /// <param name="Description">描述</param>
        /// <param name="Size">文件大小</param>
        /// <param name="CreateBy">创建人</param>
        /// <returns></returns>
        public static int UpLogo(string image, string Extension, string Description, int Size, string CreateBy)
        {
            //获取上传图片信息
            ImageModel imageModel = CommonUtils.UploadImagFile(image, Extension);

            //保存到数据库中
            string sql = @" INSERT INTO tblpartyfile (`ID`, `Title`, `Extension`, `Description`, `Size`, `Url`, `CreateTime`, `CreateBy`) VALUES (@ID, @Title, @Extension, @Description, @Size, @Url, @CreateTime, @CreateBy); ";

            string imageId = StringHelper.NewID;

            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=imageId},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Title",Value=imageModel.ImageName},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Extension",Value=Extension},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Description",Value=Description},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Size",Value=Size},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Url",Value=imageModel.ImageUrl},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=DateTime.Now},
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=CreateBy}
            };

            //同时更新用户表中的图片ID
            string update = " UPDATE tblpartyorgmember SET `ImageUrl`=@ImageUrl WHERE (`LoginID`=@LoginID); ";
            List<MySqlParameter> parametersUpdate = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ImageUrl",Value=imageId},
                new MySqlParameter() { DbType=DbType.String,ParameterName="LoginID",Value=CreateBy},
            };
            Data.MySqlHelper.ExecuteNonQuery(update, parametersUpdate.ToArray());

            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }

        public static ImageModel NewUpLogo(string image, string Extension, string Description, int Size, string CreateBy)
        {
            //获取上传图片信息
            ImageModel imageModel = CommonUtils.UploadImagFile(image, Extension);

            //保存到数据库中
            string sql = @" INSERT INTO tblpartyfile (`ID`, `Title`, `Extension`, `Description`, `Size`, `Url`, `CreateTime`, `CreateBy`) VALUES (@ID, @Title, @Extension, @Description, @Size, @Url, @CreateTime, @CreateBy); ";

            string imageId = StringHelper.NewID;

            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=imageId},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Title",Value=imageModel.ImageName},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Extension",Value=Extension},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Description",Value=Description},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Size",Value=Size},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Url",Value=imageModel.ImageUrl},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=DateTime.Now},
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=CreateBy}
            };

            //同时更新用户表中的图片ID
            string update = " UPDATE tblpartyorgmember SET `ImageUrl`=@ImageUrl WHERE (`LoginID`=@LoginID); ";
            List<MySqlParameter> parametersUpdate = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ImageUrl",Value=imageId},
                new MySqlParameter() { DbType=DbType.String,ParameterName="LoginID",Value=CreateBy},
            };

            Data.MySqlHelper.ExecuteNonQuery(update, parametersUpdate.ToArray());
            Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());

            return imageModel;
        }
        #endregion

        #region 上传图片
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="image">Base64字符编码图片</param>
        /// <param name="Extension">扩展名</param>
        /// <param name="fid">外键ID</param>
        /// <returns></returns>
        public static ImageModel UpImge(string image, string Extension)
        {
            return CommonUtils.UploadImagFile(image, Extension);
        }
        #endregion

        #region 上传图片
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="image">Base64字符编码图片</param>
        /// <param name="Extension">扩展名</param>
        /// <param name="fid">外键ID</param>
        /// <returns></returns>
        public static ImageModel UpImgeExtend(string image, string Extension)
        {
            return CommonUtils.UploadImagFileExtend(image, Extension);
        }
        #endregion

        #region 上传图片（加水印）
        /// <summary>
        /// 上传图片（加水印）
        /// </summary>
        /// <param name="image">Base64字符编码图片</param>
        /// <param name="Extension">扩展名</param>
        /// <param name="WaterMarkContent">水印文字</param>
        /// <returns></returns>
        public static ImageModel UpImageWaterMark(string image, string Extension, string WaterMarkContent)
        {
            return CommonUtils.UploadImagFileWaterMark(image, Extension, WaterMarkContent);
        }
        #endregion

        #region 根据FID获取文件数据
        public static DataTable GetPartyFileByFID(string FID)
        {
            string sql = @" SELECT * FROM tblpartyfile WHERE FID=@FID; ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="FID",Value=FID}
            };
            return Data.MySqlHelper.ExecuteDataTable(sql, parameters.ToArray());
        }
        #endregion

        #region 获取群众心声数据
        /// <summary>
        /// 获取群众心声数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static DataTable GetMassesVoice(int pageIndex, int pageSize)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize}
            };
            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS *,
                        (SELECT BranchName FROM tblpartyorgbranch WHERE BranchID=su.OneLayer) AS OneLayerName,
                        (SELECT BranchName FROM tblpartyorgbranch WHERE BranchID=su.TwoLayer) AS TwoLayerName,
                        (SELECT BranchName FROM tblpartyorgbranch WHERE BranchID=su.ThreeLayer) AS ThreeLayerName
                        from tblpartygrassrootssuggestion AS su ");
            sb.Append(" order by su.CreateTime desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return Data.MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray()).Tables[0];
        }
        #endregion

        #region 获取认领人群众心声数据
        /// <summary>
        /// 获取认领人群众心声数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="CreateBy">认领人ID</param>
        /// <returns></returns>
        public static DataTable GetUnclaimedMassesVoice(int pageIndex, int pageSize, string CreateBy)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "CreateBy",Value = CreateBy}
            };
            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS *,
                        (SELECT BranchName FROM tblpartyorgbranch WHERE BranchID=su.OneLayer) AS OneLayerName,
                        (SELECT BranchName FROM tblpartyorgbranch WHERE BranchID=su.TwoLayer) AS TwoLayerName,
                        (SELECT BranchName FROM tblpartyorgbranch WHERE BranchID=su.ThreeLayer) AS ThreeLayerName
                        from tblpartygrassrootssuggestion AS su
                        where su.Unclaimed=?CreateBy ");
            sb.Append(" order by su.CreateTime desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return Data.MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray()).Tables[0];
        }
        #endregion

        #region 获取单个群众心声数据
        public static PartyGrassrootsSuggestion GetMassesVoiceModel(string id)
        {
            DataTable dt = new DataTable();
            PartyGrassrootsSuggestion model = new PartyGrassrootsSuggestion();
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){ DbType = DbType.String,ParameterName = "ID",Value = id}
            };
            string sql = @" select *,
                            (SELECT BranchName FROM tblpartyorgbranch WHERE BranchID=su.OneLayer) AS OneLayerName,
                            (SELECT BranchName FROM tblpartyorgbranch WHERE BranchID=su.TwoLayer) AS TwoLayerName,
                            (SELECT BranchName FROM tblpartyorgbranch WHERE BranchID=su.ThreeLayer) AS ThreeLayerName
                            from tblpartygrassrootssuggestion AS su where su.ID=@ID ";
            dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.ID = dr["ID"].ToString();
                model.Status = Convert.ToInt32(dr["Status"]);
                model.Reply = dr["Reply"].ToString();
                model.Gender = dr["Gender"].ToString();
                model.Age = Convert.ToInt32(dr["Age"]);
                model.Address = dr["Address"].ToString();
                model.Zip = dr["Zip"].ToString();
                model.PoliticsLineament = dr["PoliticsLineament"].ToString();
                model.HandlerBy = dr["HandlerBy"].ToString();
                model.Receiver = dr["Receiver"].ToString();
                model.CollectionTime = Convert.ToDateTime(dr["CollectionTime"]);
                model.ItemID = dr["ItemID"].ToString();
                model.MassComment = dr["MassComment"].ToString();
                model.CreateBy = dr["CreateBy"].ToString();
                model.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                model.ModifyBy = dr["ModifyBy"].ToString();
                model.ModifyTime = Convert.ToDateTime(dr["ModifyTime"]);
                model.publicity = Convert.ToInt32(dr["publicity"]);
                model.BranchID = dr["BranchID"].ToString();
                model.Image = dr["Image"].ToString();
                model.SerialNumber = dr["SerialNumber"].ToString();
                model.UserName = dr["UserName"].ToString();
                model.Title = dr["Title"].ToString();
                model.MobileNo = dr["MobileNo"].ToString();
                model.WorkUnit = dr["WorkUnit"].ToString();
                model.Post = dr["Post"].ToString();
                model.Content = dr["Content"].ToString();
                model.OneLayerName = dr["OneLayerName"].ToString();
                model.TwoLayerName = dr["TwoLayerName"].ToString();
                model.ThreeLayerName = dr["ThreeLayerName"].ToString();

                DataTable dtfile = InterfaceHelper.GetPartyFileByFID(model.ID);
                List<string> newlist = new List<string>();
                foreach (DataRow item in dtfile.Rows)
                {
                    newlist.Add(item["Url"].ToString());
                }
                model.PicList = newlist;
            }
            return model;
        }
        #endregion

        #region 群众心声保存事件
        /// <summary>
        /// 群众心声保存事件
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns></returns>
        public static int MassesVoiceSave(PartyGrassrootsSuggestion model)
        {
            string sql = @" INSERT INTO `tblpartygrassrootssuggestion` 
                        (`ID`, `ItemID`, `SerialNumber`, `UserName`, `Title`, `MobileNo`, `WorkUnit`, `Post`, `Content`, `Status`, `Reply`, `Gender`, `Age`, `Address`, `Zip`, `PoliticsLineament`, `HandlerBy`, `Receiver`, `CollectionTime`, `MassComment`, `CreateBy`, `CreateTime`, `ModifyBy`, `ModifyTime`, `Image`, `OneLayer`, `TwoLayer`, `ThreeLayer`) 
                           VALUES (@ID, @ItemID, @SerialNumber, @UserName, @Title, @MobileNo, @WorkUnit, @Post, @Content, @Status, @Reply, @Gender, @Age, @Address, @Zip, @PoliticsLineament, @HandlerBy, @Receiver, @CollectionTime, @MassComment, @CreateBy, @CreateTime, @ModifyBy, @ModifyTime, @Image, @OneLayer, @TwoLayer, @ThreeLayer) ";

            List<MySqlParameter> parameters = new List<MySqlParameter>() {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ItemID",Value=model.ItemID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="SerialNumber",Value=model.SerialNumber},
                new MySqlParameter() { DbType=DbType.String,ParameterName="UserName",Value=model.UserName},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Title",Value=model.Title},
                new MySqlParameter() { DbType=DbType.String,ParameterName="MobileNo",Value=model.MobileNo},
                new MySqlParameter() { DbType=DbType.String,ParameterName="WorkUnit",Value=model.WorkUnit},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Post",Value=model.Post},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Content",Value=model.Content},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Status",Value=model.Status},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Reply",Value=model.Reply},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Gender",Value=model.Gender},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Age",Value=model.Age},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Address",Value=model.Address},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Zip",Value=model.Zip},
                new MySqlParameter() { DbType=DbType.String,ParameterName="PoliticsLineament",Value=model.PoliticsLineament},
                new MySqlParameter() { DbType=DbType.String,ParameterName="HandlerBy",Value=model.HandlerBy},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Receiver",Value=model.Receiver},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CollectionTime",Value=model.CollectionTime},
                new MySqlParameter() { DbType=DbType.String,ParameterName="MassComment",Value=model.MassComment},
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=model.CreateBy},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ModifyBy",Value=model.ModifyBy},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="ModifyTime",Value=model.ModifyTime},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Image",Value=model.Image},
                new MySqlParameter() { DbType=DbType.String,ParameterName="OneLayer",Value=model.OneLayer},
                new MySqlParameter() { DbType=DbType.String,ParameterName="TwoLayer",Value=model.TwoLayer},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ThreeLayer",Value=model.ThreeLayer}
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 获取群众心声详情数据
        /// <summary>
        /// 获取群众心声详情数据
        /// </summary>
        /// <param name="sid">外键ID</param>
        /// <returns></returns>
        public static DataTable GetMassesVoiceDetail(string sid)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="SID",Value=sid}
            };
            string sql = @" SELECT de.*,
                            (SELECT BranchName FROM tblpartyorgbranch WHERE ParentBranchID = '') AS OneLayerName,
							if((SELECT BranchName FROM tblpartyorgbranch WHERE BranchID= (SELECT ParentBranchID FROM tblpartyorgbranch WHERE BranchID=member.BranchID) ) IS NULL,'山海天',(SELECT BranchName FROM tblpartyorgbranch WHERE BranchID= (SELECT ParentBranchID FROM tblpartyorgbranch WHERE BranchID=member.BranchID) )) AS TwoLayerName,
                            (SELECT BranchName FROM tblpartyorgbranch WHERE BranchID = member.BranchID) AS ThreeLayerName
                            FROM tblpartygrassrootssuggestion AS su
                            RIGHT JOIN tblpartygrassrootssuggestiondetail AS de
                            ON su.ID = de.SID
                            LEFT JOIN tblpartyorgmember as member
                            ON member.ID = de.CreateBy
                            WHERE de.SID=@SID ORDER BY de.CreateTime ASC  ";
            return Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
        }
        #endregion

        #region 根据ID修改群众心声状态
        /// <summary>
        /// 根据ID修改群众心声状态
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int UpdateMassesVoiceStatusByID(PartyGrassrootsSuggestion model)
        {
            string sql = @" UPDATE `tblpartygrassrootssuggestion` SET `Status`=@Status, `Unclaimed`=@Unclaimed WHERE (`ID`=@ID);";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Status",Value=model.Status},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Unclaimed",Value=model.Unclaimed},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID}
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 根据SID删除群众心声详情表
        /// <summary>
        /// 根据SID删除群众心声详情表
        /// </summary>
        /// <param name="SID"></param>
        /// <returns></returns>
        public static int DeleteMassesVoiceDetailBySID(string SID)
        {
            string sql = @" DELETE FROM tblpartygrassrootssuggestiondetail WHERE SID=@SID; ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="SID",Value=SID}
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 添加群众心声详情表
        /// <summary>
        /// 添加群众心声详情表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int AddMassesVoiceDetail(PartyGrassrootsSuggestionDetail model)
        {
            string sql = @" INSERT INTO `tblpartygrassrootssuggestiondetail` (`ID`, `SID`, `Content`, `CreateBy`, `CreateTime`, `Status`) VALUES (@ID, @SID, @Content, @CreateBy, @CreateTime, @Status); ";
            List<MySqlParameter> parameters = new List<MySqlParameter>() {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="SID",Value=model.SID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Content",Value=model.Content },
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=model.CreateBy },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Status",Value=model.Status }
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 添加文件表
        public static int AddFileTalbe(PartyFile model)
        {
            string sql = @" INSERT INTO `tblpartyfile` (`ID`, `Title`, `Extension`, `Description`, `Size`, `Url`, `CreateTime`, `CreateBy`, `ModifyTime`, `ModifyBy`, `FID`) VALUES (@ID, @Title, @Extension, @Description, @Size, @Url, @CreateTime, @CreateBy, @ModifyTime, @ModifyBy, @FID) ";

            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="ModifyBy",Value=model.ModifyBy },
                new MySqlParameter() { DbType=DbType.String,ParameterName="FID",Value=model.FID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Title",Value=model.Title },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Extension",Value=model.Extension },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Description",Value=model.Description },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Size",Value=model.Size },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Url",Value=model.Url },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime },
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=model.CreateBy },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="ModifyTime",Value=model.ModifyTime }
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 获取所有组织
        /// <summary>
        /// 获取所有组织
        /// </summary>
        /// <returns></returns>
        public static DataTable GetAllBranch()
        {
            dtMenu = null;
            dtNewMenu = null;
            layer = 0;
            string sql = @" select * from tblPartyOrgBranch where ParentBranchID='' ORDER BY OrderNo; ";
            dtMenu = Data.MySqlHelper.ExecuteDataSet(sql).Tables[0];
            dtNewMenu = CommonUtils.CopyDataTable(dtMenu);

            for (int i = 0; i < dtMenu.Rows.Count; i++)
            {
                DataRow dr = dtMenu.Rows[i];
                GetAllChildBranch(dr["BranchID"].ToString());
            }
            return dtNewMenu;
        }
        #endregion

        #region 获取所有组织子菜单
        /// <summary>
        /// 获取所有组织子菜单
        /// </summary>
        /// <param name="id">组织ID</param>
        /// <returns></returns>
        public static DataTable GetAllChildBranch(string id)
        {
            layer++;//层级
            string sql = @" select * from tblPartyOrgBranch WHERE ParentBranchID=@ParentBranchID ORDER BY OrderNo; ";

            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.String,ParameterName = "ParentBranchID",Value = id}
            };
            DataTable dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];

            //把子菜单追加到DataTable下方
            foreach (DataRow itemChild in dt.Rows)
            {
                DataRow newRow;
                newRow = dtNewMenu.NewRow();
                newRow["BranchID"] = itemChild["BranchID"];

                StringBuilder layersb = new StringBuilder();
                for (int j = 0; j < layer; j++)
                {
                    layersb.Append("-");
                }
                string NewBranchName = layersb.ToString() + itemChild["BranchName"];
                layersb.Length = 0;
                newRow["BranchName"] = NewBranchName;
                newRow["ParentBranchID"] = itemChild["ParentBranchID"];
                newRow["OrderNo"] = itemChild["OrderNo"];
                newRow["ImageUrl"] = itemChild["ImageUrl"];
                newRow["CreateTime"] = itemChild["CreateTime"];
                dtNewMenu.Rows.Add(newRow);

                bool b = IsHaveChildBranch(itemChild["BranchID"].ToString());
                if (b)
                    GetAllChildBranch(itemChild["BranchID"].ToString());
            }

            return dt;
        }
        #endregion

        #region 是否有子组织
        public static bool IsHaveChildBranch(string id)
        {
            bool result = false;
            string sql = @" select * from tblPartyOrgBranch where ParentBranchID=@ParentBranchID ORDER BY OrderNo; ";

            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.String,ParameterName = "ParentBranchID",Value = id}
            };
            DataTable dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
                result = true;
            else
                result = false;

            return result;
        }
        #endregion

        #region 根据条件获取组织
        public static DataTable GetBranchListWhereBranchName(string branchName)
        {
            string sql = string.Format(" select * from tblPartyOrgBranch where BranchName LIKE '%{0}%'  ORDER BY OrderNo; ", branchName);
            return Data.MySqlHelper.ExecuteDataSet(sql).Tables[0];
        }
        #endregion

        #region 根据ParentBranchID获取组织
        /// <summary>
        /// 根据ParentBranchID获取组织
        /// </summary>
        /// <param name="ParentBranchID">组织父ID</param>
        /// <returns></returns>
        public static DataTable GetBranchListWhereParentBranchID(string ParentBranchID)
        {
            string sql = @" SELECT * FROM tblPartyOrgBranch WHERE ParentBranchID = @ParentBranchID order by OrderNo,BranchName ";
            List<MySqlParameter> parameters = new List<MySqlParameter>() {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ParentBranchID",Value=ParentBranchID}
            };
            return Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
        }
        #endregion

        #region 获取留言板数据
        /// <summary>
        /// 获取留言板数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="CreateBy">创建人ID</param>
        /// <returns></returns>
        public static DataTable GetMessageBoard(int pageIndex, int pageSize, string CreateBy)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "CreateBy",Value = CreateBy}
            };

            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS * from tblPartyMessageBoard
                        where Title <> '' and CreateBy=?CreateBy ");
            sb.Append(" order by CreateTime desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return Data.MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray()).Tables[0];
        }
        #endregion

        #region 获取单个留言板数据
        public static PartyMessageBoard GetMessageBoardModel(string id)
        {
            DataTable dt = new DataTable();
            PartyMessageBoard model = new PartyMessageBoard();
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){ DbType = DbType.String,ParameterName = "ID",Value = id}
            };
            string sql = @" select message.*,branch.BranchName from tblPartyMessageBoard message
                            left join tblpartyorgbranch branch on message.BranchID=branch.BranchID 
                            where message.ID=@ID ";
            dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.ID = dr["ID"].ToString();
                model.HandleBy = dr["HandleBy"].ToString();
                //model.HandleTime = Convert.ToDateTime(dr["HandleTime"]);
                model.HandleContent = dr["HandleContent"].ToString();
                model.MessageState = Convert.ToInt32(dr["MessageState"]);
                model.Image = dr["Image"].ToString();
                model.UserName = dr["UserName"].ToString();
                model.MobileNo = dr["MobileNo"].ToString();
                model.BranchID = dr["BranchID"].ToString();
                model.Message = dr["Message"].ToString();
                model.CreateBy = dr["CreateBy"].ToString();
                model.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                model.ModifyBy = dr["ModifyBy"].ToString();
                //model.ModifyTime = Convert.ToDateTime(dr["ModifyTime"]);
                model.Title = dr["Title"].ToString();
                model.BranchName = dr["BranchName"].ToString();

                DataTable dtfile = InterfaceHelper.GetPartyFileByFID(model.ID);
                List<string> newlist = new List<string>();
                foreach (DataRow item in dtfile.Rows)
                {
                    newlist.Add(item["Url"].ToString());
                }
                model.PicList = newlist;
            }
            return model;
        }
        #endregion

        #region 留言板保存事件
        public static int MessageBoardSave(PartyMessageBoard model)
        {
            string sql = @" INSERT INTO `tblPartyMessageBoard` (`ID`, `UserName`, `MobileNo`, `BranchID`, `Message`, `CreateBy`, `CreateTime`, `ModifyBy`, `ModifyTime`, `HandleBy`, `HandleTime`,               `HandleContent`, `MessageState`, `Image`, `Title`) 
                            VALUES (@ID, @UserName, @MobileNo, @BranchID, @Message, @CreateBy, @CreateTime, @ModifyBy, @ModifyTime, @HandleBy, @HandleTime, @HandleContent, @MessageState, @Image,@Title) ";

            List<MySqlParameter> parameters = new List<MySqlParameter>() {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="UserName",Value=model.UserName},
                new MySqlParameter() { DbType=DbType.String,ParameterName="MobileNo",Value=model.MobileNo},
                new MySqlParameter() { DbType=DbType.String,ParameterName="BranchID",Value=model.BranchID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Message",Value=model.Message},
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=model.CreateBy},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ModifyBy",Value=model.ModifyBy},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="ModifyTime",Value=model.ModifyTime},
                new MySqlParameter() { DbType=DbType.String,ParameterName="HandleBy",Value=model.HandleBy},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="HandleTime",Value=model.HandleTime},
                new MySqlParameter() { DbType=DbType.String,ParameterName="HandleContent",Value=model.HandleContent},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="MessageState",Value=model.MessageState},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Image",Value=model.Image},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Title",Value=model.Title}
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 获取学习课件数据
        /// <summary>
        /// 获取学习课件数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="Category">分类</param>
        /// <returns></returns>
        public static DataSet GetPartyEduCourseware(int pageIndex, int pageSize, string Category)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Category",Value=Category}
            };
            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS temp.ID,temp.Title,temp.StatusName,temp.CreateTime,temp.Category,file.Url AS ImageID from 
(select a.*,if(a.Status=4,'已发布','草稿') as StatusName,(select FileID from tblpartyeducoursewareimage m where m.CoursewareID=a.id order by FileType desc limit 1 ) as ImageID
                    from tblpartyeducourseware a where a.CourseType='Video' ) as temp
LEFT JOIN  tblpartyfile AS file ON temp.ImageID=file.ID WHERE temp.Category=@Category ");

            sb.Append(" ORDER BY temp.CreateTime desc  LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return Data.MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray());
        }
        #endregion

        #region 获取单个学习课件数据
        public static PartyEduCourseware GetPartyEduCoursewareModel(string id)
        {
            DataTable dt = new DataTable();
            PartyEduCourseware model = new PartyEduCourseware();
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){ DbType = DbType.String,ParameterName = "ID",Value = id}
            };
            string sql = @" select 
                            cour.ID,cour.Title,cour.Module,cour.Category,cour.CourseType,cour.Duration,cour.TargetObject,cour.Summary,
                            cour.FileID,cour.ImageUrl,cour.Flags,cour.Status,cour.CreateTime,cour.CreateBy,cour.ClickCount,
                            file.Title as FileName ,file.Url
                            from tblpartyeducourseware as cour
                            LEFT JOIN tblpartyfile file
                            on cour.FileID=file.ID WHERE cour.ID=@ID ";
            dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                //学习课件实体赋值
                model.ID = dr["ID"].ToString();
                model.Title = dr["Title"].ToString();
                model.Module = dr["Module"].ToString();
                model.Category = dr["Category"].ToString();
                model.CourseType = dr["CourseType"].ToString();
                model.Duration = dr["Duration"].ToString();
                model.TargetObject = dr["TargetObject"].ToString();
                model.Summary = dr["Summary"].ToString();
                model.FileID = dr["FileID"].ToString();
                model.ImageUrl = dr["ImageUrl"].ToString();
                model.Flags = Convert.ToInt32(dr["Flags"]);
                model.Status = Convert.ToInt32(dr["Status"]);
                model.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                model.CreateBy = dr["CreateBy"].ToString();
                model.ClickCount = Convert.ToInt32(dr["ClickCount"]);
                //文件实体赋值
                model.FileName = dr["FileName"].ToString();
                model.Url = dr["Url"].ToString();
            }
            return model;
        }
        #endregion

        #region 获取三会一课数据
        /// <summary>
        /// 获取三会一课数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="loginId">用户ID</param>
        /// <param name="IsEnd">活动是否结束（0：未结束1：已结束2：全部）</param>
        /// <returns></returns>
        public static DataSet GetMeetingLecture(int pageIndex, int pageSize, string loginId, int IsEnd = 2)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize}
            };

            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS  meeting.ID,Title,BeginTime,EndTime,meeting.CreateTime,if(IsEnd=1,'是','否') as IsEndName,BranchName,
                        case MeetType when '0' then '党员大会' when '1' then '支部委员会' when '2' then '党小组小组会' end as MeetingTypeName
                        from tblpartymeetinglecture meeting
                        left join tblpartyorgbranch branch on meeting.BranchID=branch.BranchID
                        left join tblpartymeetinglecturemember member on member.MeetingLectureID=meeting.ID
                        where 1=1 ");

            if (!string.IsNullOrEmpty(loginId))
            {
                sb.AppendFormat(" and member.LoginID='{0}'", loginId);
            }
            if (IsEnd == 0)
            {//显示未结束的活动
                sb.Append(" and meeting.IsEnd=?IsEnd ");
                parameters.Add(new MySqlParameter() { DbType = DbType.Boolean, ParameterName = "IsEnd", Value = false });
            }
            else if (IsEnd == 1)
            {//显示已结束的活动
                sb.Append(" and meeting.IsEnd=?IsEnd ");
                parameters.Add(new MySqlParameter() { DbType = DbType.Boolean, ParameterName = "IsEnd", Value = true });
            }
            sb.Append(" order by meeting.CreateTime desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return Data.MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray());
        }
        #endregion

        #region 获取单个三会一课数据
        public static PartyMeetingLecture GetMeetingLectureModel(string id)
        {
            DataTable dt = new DataTable();
            PartyMeetingLecture model = new PartyMeetingLecture();
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){ DbType = DbType.String,ParameterName = "ID",Value = id}
            };
            string sql = @" SELECT meeting.*,branch.BranchName from tblPartyMeetingLecture meeting
                            left join tblpartyorgbranch branch on meeting.BranchID=branch.BranchID WHERE meeting.ID=@ID ";
            dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.ID = dr["ID"].ToString();
                model.Coordinate = dr["Coordinate"].ToString();
                model.SmsContent = dr["SmsContent"].ToString();
                model.ImageID = dr["ImageID"].ToString();
                model.Record = dr["Record"].ToString();
                model.Flags = Convert.ToInt32(dr["Flags"]);
                model.Status = Convert.ToInt32(dr["Status"]);
                model.Aduit = Convert.ToInt32(dr["Aduit"]);
                model.BranchID = dr["BranchID"].ToString();
                model.RelationID = dr["RelationID"].ToString();
                model.ModifyBy = dr["ModifyBy"].ToString();
                model.CreateBy = dr["CreateBy"].ToString();
                model.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                model.ModifyTime = Convert.ToDateTime(dr["ModifyTime"]);
                model.Title = dr["Title"].ToString();
                model.Category = dr["Category"].ToString();
                model.MeetType = dr["MeetType"].ToString();
                model.Summary = dr["Summary"].ToString();
                model.BeginTime = Convert.ToDateTime(dr["BeginTime"]);
                model.EndTime = Convert.ToDateTime(dr["EndTime"]);
                model.Address = dr["Address"].ToString();
                model.IsEnd = Convert.ToBoolean(dr["IsEnd"]);
                model.BranchName = dr["BranchName"].ToString();
            }
            return model;
        }
        #endregion

        #region 获取三会一课数量
        public static int GetMeetingLectureCount(string loginId, int IsEnd = 2)
        {
            DataTable dt = new DataTable();
            List<MySqlParameter> parameters = new List<MySqlParameter>() { };
            StringBuilder sb = new StringBuilder();
            sb.Append(@"select  COUNT(meeting.ID) as num
                        from tblpartymeetinglecture meeting
                        left join tblpartyorgbranch branch on meeting.BranchID=branch.BranchID
                        left join tblpartymeetinglecturemember member on member.MeetingLectureID=meeting.ID
                        where 1=1 ");

            if (!string.IsNullOrEmpty(loginId))
            {
                sb.AppendFormat(" and member.LoginID='{0}'", loginId);
            }
            if (IsEnd == 0)
            {//显示未结束的活动
                sb.Append(" and meeting.IsEnd=?IsEnd ");
                parameters.Add(new MySqlParameter() { DbType = DbType.Boolean, ParameterName = "IsEnd", Value = false });
            }
            else if (IsEnd == 1)
            {//显示已结束的活动
                sb.Append(" and meeting.IsEnd=?IsEnd ");
                parameters.Add(new MySqlParameter() { DbType = DbType.Boolean, ParameterName = "IsEnd", Value = true });
            }
            object obj = Data.MySqlHelper.ExecuteScalar(sb.ToString(), parameters.ToArray());
            int num = 0;
            if (obj != null)
                num = Convert.ToInt32(obj);
            return num;
        }
        #endregion

        #region 获取三会一课人员数据根据MeetingLectureID
        /// <summary>
        /// 获取三会一课人员数据根据MeetingLectureID
        /// </summary>
        /// <param name="MeetingLectureID"></param>
        /// <returns></returns>
        public static DataTable GetMeetingLectureMemberByMeetingLectureID(string MeetingLectureID)
        {
            DataTable dt = new DataTable();
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){ DbType = DbType.String,ParameterName = "MeetingLectureID",Value = MeetingLectureID}
            };
            string sql = @" SELECT * FROM tblpartymeetinglecturemember WHERE MeetingLectureID=@MeetingLectureID; ";
            dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            return dt;
        }
        #endregion

        #region 获取会议记录数据
        /// <summary>
        /// 获取会议记录数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="FID">外键ID</param>
        /// <returns></returns>
        public static DataTable GetMeetingLectureRecord(int pageIndex, int pageSize, string FID)
        {
            StringBuilder sb = new StringBuilder();
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="FID",Value=FID},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize}
            };
            sb.Append(@" SELECT SQL_CALC_FOUND_ROWS record.*,record.Record AS Title FROM tblpartymeetinglecturerecord AS record
                            LEFT JOIN tblpartymeetinglecture AS meeting
                            ON record.FID=meeting.ID where record.FID=@FID ");
            sb.Append(" order by record.CreateTime desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return Data.MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray()).Tables[0];
        }
        #endregion

        #region 获取会议记录实体
        /// <summary>
        /// 获取会议记录实体
        /// </summary>
        /// <param name="ID">ID</param>
        /// <returns></returns>
        public static PartyMeetingLectureRecord GetMeetingLectureRecordModel(string ID)
        {
            DataTable dt = new DataTable();
            PartyMeetingLectureRecord model = new PartyMeetingLectureRecord();
            string sql = @" SELECT * FROM tblpartymeetinglecturerecord WHERE ID=@ID; ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=ID}
            };
            dt = Data.MySqlHelper.ExecuteDataTable(sql, parameters.ToArray());
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.ID = dr["ID"].ToString();
                model.FID = dr["FID"].ToString();
                model.Record = dr["Record"].ToString();
                model.CreateBy = dr["CreateBy"].ToString();
                model.CreateTime = Convert.ToDateTime(dr["CreateTime"]);

                DataTable dtfile = InterfaceHelper.GetPartyFileByFID(model.ID);
                List<string> newlist = new List<string>();
                foreach (DataRow item in dtfile.Rows)
                {
                    newlist.Add(item["Url"].ToString());
                }
                model.PicList = newlist;
            }
            return model;
        }
        #endregion

        #region 保存会议记录
        public static int MeetingLectureRecordSave(PartyMeetingLectureRecord model)
        {
            string sql = @" INSERT INTO `tblpartymeetinglecturerecord` (`ID`, `FID`, `Record`, `CreateBy`, `CreateTime`) VALUES (@ID, @FID, @Record, @CreateBy, @CreateTime); ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="FID",Value=model.FID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Record",Value=model.Record},
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=model.CreateBy},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime}
            };

            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 获取支部活动数据
        /// <summary>
        /// 获取支部活动数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="loginId">用户ID</param>
        /// <param name="branchId">支部ID</param>
        /// <param name="IsEnd">活动是否结束（0：未结束1：已结束2：全部）</param>
        /// <returns></returns>
        public static DataSet GetBranchActivity(int pageIndex, int pageSize, string loginId, string branchId = "", int IsEnd = 2)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize}
            };

            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS  a.ID,Title,BeginTime,EndTime,a.CreateTime,if(IsEnd=1,'是','否') as IsEndName,BranchName,
                        if(Flags=1,'是','否') as FlagsName,DDicMemberName as ThematicName
                        from tblpartybranchactivitie a
                        left join tblpartyorgbranch b on a.BranchID=b.BranchID
                        left join tblpartybranchactivitiemember m on m.ActivitieID=a.ID
                        left join tbldatadictionary d on DDicType='ZHDJ.BranchActivity.Thematic' and DDicMember=Thematic
                        where 1=1 ");

            if (!string.IsNullOrEmpty(loginId))
            {
                sb.AppendFormat(" and m.LoginID='{0}'", loginId);
            }
            if (!string.IsNullOrEmpty(branchId))
            {
                sb.Append(" and a.BranchID in (select childbranchid from tblpartyorgbranchrelation a where a.BranchID=?BranchID)");
                parameters.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "BranchID", Value = branchId });
            }
            if (IsEnd == 0)
            {//显示未结束的活动
                sb.Append(" and a.IsEnd=?IsEnd ");
                parameters.Add(new MySqlParameter() { DbType = DbType.Boolean, ParameterName = "IsEnd", Value = false });
            }
            else if (IsEnd == 1)
            {//显示已结束的活动
                sb.Append(" and a.IsEnd=?IsEnd ");
                parameters.Add(new MySqlParameter() { DbType = DbType.Boolean, ParameterName = "IsEnd", Value = true });
            }
            sb.Append(" order by a.CreateTime desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return Data.MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray());
        }
        #endregion

        #region 获取单个支部活动数据
        public static PartyBranchActivitie GetBranchActivityModel(string id)
        {
            DataTable dt = new DataTable();
            PartyBranchActivitie model = new PartyBranchActivitie();
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){ DbType = DbType.String,ParameterName = "ID",Value = id}
            };
            string sql = @" select a.*,branch.BranchName,DDicMemberName as ThematicName from tblpartybranchactivitie a
                            left join tblpartyorgbranch branch on a.BranchID=branch.BranchID
                            left join tbldatadictionary d on DDicType='ZHDJ.BranchActivity.Thematic' and DDicMember=Thematic WHERE a.ID=@ID ";
            dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.ID = dr["ID"].ToString();
                model.SmsContent = dr["SmsContent"].ToString();
                model.ImageID = dr["ImageID"].ToString();
                model.Record = dr["Record"].ToString();
                model.Flags = Convert.ToInt32(dr["Flags"]);
                model.Status = Convert.ToInt32(dr["Status"]);
                model.Aduit = Convert.ToInt32(dr["Aduit"]);
                model.RelationID = dr["RelationID"].ToString();
                model.BranchID = dr["BranchID"].ToString();
                model.CreateBy = dr["CreateBy"].ToString();
                model.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                model.ModifyTime = Convert.ToDateTime(dr["ModifyTime"]);
                model.ModifyBy = dr["ModifyBy"].ToString();
                model.Title = dr["Title"].ToString();
                model.Thematic = dr["Thematic"].ToString();
                model.Summary = dr["Summary"].ToString();
                model.BeginTime = Convert.ToDateTime(dr["BeginTime"]);
                model.EndTime = Convert.ToDateTime(dr["EndTime"]);
                model.Address = dr["Address"].ToString();
                model.Coordinate = dr["Coordinate"].ToString();
                model.BranchName = dr["BranchName"].ToString();
                model.ThematicName = dr["ThematicName"].ToString();
            }
            return model;
        }
        #endregion

        #region 获取支部活动数量
        /// <summary>
        /// 获取支部活动数量
        /// </summary>
        /// <param name="loginId">用户ID</param>
        /// <param name="branchId">支部ID</param>
        /// <param name="IsEnd">活动是否结束（0：未结束1：已结束2：全部）</param>
        /// <returns></returns>
        public static int GetBranchActivityCount(string loginId, string branchId = "", int IsEnd = 2)
        {
            DataTable dt = new DataTable();
            List<MySqlParameter> parameters = new List<MySqlParameter>() { };
            StringBuilder sb = new StringBuilder();
            sb.Append(@"select COUNT(a.ID) as num
                        from tblpartybranchactivitie a
                        left join tblpartyorgbranch b on a.BranchID=b.BranchID
                        left join tblpartybranchactivitiemember m on m.ActivitieID=a.ID
                        left join tbldatadictionary d on DDicType='ZHDJ.BranchActivity.Thematic' and DDicMember=Thematic
                        where 1=1 ");

            if (!string.IsNullOrEmpty(loginId))
            {
                sb.AppendFormat(" and m.LoginID='{0}'", loginId);
            }
            if (!string.IsNullOrEmpty(branchId))
            {
                sb.Append(" and a.BranchID in (select childbranchid from tblpartyorgbranchrelation a where a.BranchID=?BranchID)");
                parameters.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "BranchID", Value = branchId });
            }
            if (IsEnd == 0)
            {//显示未结束的活动
                sb.Append(" and a.IsEnd=?IsEnd ");
                parameters.Add(new MySqlParameter() { DbType = DbType.Boolean, ParameterName = "IsEnd", Value = false });
            }
            else if (IsEnd == 1)
            {//显示已结束的活动
                sb.Append(" and a.IsEnd=?IsEnd ");
                parameters.Add(new MySqlParameter() { DbType = DbType.Boolean, ParameterName = "IsEnd", Value = true });
            }
            object obj = Data.MySqlHelper.ExecuteScalar(sb.ToString(), parameters.ToArray());
            int num = 0;
            if (obj != null)
                num = Convert.ToInt32(obj);
            return num;
        }
        #endregion

        #region 获取我的组织名称
        public static string GetBranchNameBId(string BranchID)
        {
            string result = "";
            var para = new List<MySqlParameter>
            {
                new MySqlParameter(){DbType = DbType.String,ParameterName = "BranchID",Value = BranchID},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "DDicType1",Value = SysDataDictionary.BranchTypeKey},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "DDicType2",Value = SysDataDictionary.BranchMarkKey}
            };
            var sql = new StringBuilder(@"SELECT  d.*,dd.BranchName ParentBranchIName,
                            dic.DDicMemberName as BranchTypeName,dic2.DDicMemberName as BranchMarkName
                            
                            FROM tblpartyorgbranch d
                            left join tblpartyorgbranch dd on (dd.branchID=d.ParentBranchID)
                            left join tbldatadictionary dic on (dic.DDicType=?DDicType1 and dic.DDicMember=d.BranchType)
                            left join tbldatadictionary dic2 on (dic2.DDicType=?DDicType2 and dic2.DDicMember=d.BranchMark)    
                            WHERE d.BranchID=?BranchID ;                       
                            ");
            DataTable dt = Data.MySqlHelper.ExecuteDataSet(sql.ToString(), para.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
                result = dt.Rows[0]["BranchName"].ToString();
            return result;
        }
        #endregion

        #region 获取我的积分
        /// <summary>
        /// 根据所属人获取积分总数
        /// </summary>
        /// <param name="ObjectType">积分类型（组织积分、个人积分）</param>
        /// <param name="CreateBy">获得积分的人/组织ID</param>
        /// <returns></returns>
        public static double SumMemberintegral(string ObjectType, string ObjectID)
        {
            double sum = 0;
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ObjectType",Value=ObjectType},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ObjectID",Value=ObjectID}
            };

            StringBuilder sb = new StringBuilder();
            sb.Append(" select SUM(Score) from tblpartyobjectscore where ObjectType=@ObjectType AND ObjectID=@ObjectID ");

            object ob = Data.MySqlHelper.ExecuteScalar(sb.ToString(), parameters.ToArray());
            if (ob != null)
                sum = Convert.ToDouble(ob);
            return sum;
        }
        #endregion

        #region 获取总排名
        /// <summary>
        /// 获取当前所属人的总排名
        /// </summary>
        /// <param name="ObjectType"></param>
        /// <param name="ObjectID"></param>
        /// <returns></returns>
        public static int GetRankingByObjectID(string ObjectType, string ObjectID)
        {
            int rank = 0;
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ObjectType",Value=ObjectType},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ObjectID",Value=ObjectID}
            };

            StringBuilder sb = new StringBuilder();
            sb.Append(@" SELECT rowobj.rownum FROM
                        (SELECT obj.ObjectID,SumScore,
                         CASE 
                         WHEN @rowtotal = obj.SumScore THEN
                              @rownum
                         WHEN @rowtotal := obj.SumScore THEN
                              @rownum :=@rownum + 1
                         WHEN @rowtotal = 0 THEN
                              @rownum :=@rownum + 1
                         END AS rownum
                         FROM 
                        (SELECT ObjectID,Score,SUM(Score) AS SumScore FROM tblpartyobjectscore WHERE ObjectType=@ObjectType  
                         GROUP BY ObjectID ORDER BY SUM(Score) DESC ) AS obj,
                        (SELECT @rownum := 0 ,@rowtotal := NULL) r
                        ) AS rowobj WHERE rowobj.ObjectID=@ObjectID ");

            object ob = Data.MySqlHelper.ExecuteScalar(sb.ToString(), parameters.ToArray());
            if (ob != null)
                rank = Convert.ToInt32(ob);
            return rank;
        }
        #endregion

        #region 获取组织内排名
        /// <summary>
        /// 获取当前所属人的组织内排名
        /// </summary>
        /// <param name="ObjectType"></param>
        /// <param name="ObjectID"></param>
        /// <param name="BranchID"></param>
        /// <returns></returns>
        public static int GetRankingByObjectID(string ObjectType, string ObjectID, string BranchID)
        {
            int rank = 0;
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ObjectType",Value=ObjectType},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ObjectID",Value=ObjectID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="BranchID",Value=BranchID}
            };
            StringBuilder sb = new StringBuilder();
            sb.Append(@" SELECT rowobj.rownum FROM
                        (SELECT obj.ObjectID,SumScore,
                         CASE 
                         WHEN @rowtotal = obj.SumScore THEN
                              @rownum
                         WHEN @rowtotal := obj.SumScore THEN
                              @rownum :=@rownum + 1
                         WHEN @rowtotal = 0 THEN
                              @rownum :=@rownum + 1
                         END AS rownum
                         FROM (select ObjectID,SUM(Score) AS SumScore from tblpartyorgmember as m INNER JOIN tblpartyobjectscore as s on m.LoginID = s.ObjectID  
                         WHERE ObjectType=@ObjectType and BranchID=@BranchID GROUP BY ObjectID ORDER BY SUM(Score) DESC ) AS obj,
                        (SELECT @rownum := 0 ,@rowtotal := NULL) r
                        ) AS rowobj WHERE rowobj.ObjectID=@ObjectID ");
            object ob = Data.MySqlHelper.ExecuteScalar(sb.ToString(), parameters.ToArray());
            if (ob != null)
                rank = Convert.ToInt32(ob);
            return rank;
        }
        #endregion

        #region 获取我的党费缴纳记录
        /// <summary>
        /// 获取我的党费缴纳记录
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="LoginID">用户ID</param>
        /// <returns></returns>
        public static DataTable GetMyMemberCost(int pageIndex, int pageSize, string LoginID)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "LoginID",Value = LoginID }
            };
            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS  * from tblPartyMemberCost where LoginID=?LoginID ");
            sb.Append(" order by PayDate desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return Data.MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray()).Tables[0];
        }
        #endregion

        #region 获取生成验证码
        public static string GetValiCode(string _UserName)
        {
            var md5 = EncryptionUtil.StringToMD5Hash(_UserName).ToUpper();
            return md5.Substring(0, 5) + md5.Substring(15, 5);
        }
        #endregion

        #region 获取党费缴纳日期
        /// <summary>
        /// 获取党费缴纳日期
        /// </summary>
        /// <param name="loginID"></param>
        /// <returns></returns>
        public static string GetMemberCostDate(string loginID)
        {
            StringBuilder sbSql = new StringBuilder();
            List<MySqlParameter> parameters = new List<MySqlParameter>();

            sbSql.Append(@"select CONCAT(YEAR,'-',Month) as PayDate from tblPartyMemberCost cost
inner join tblPartyOrgMember member on cost.LoginID=member.LoginID
where PayDate is not null and cost.LoginID=?LoginID
order by YEAR desc ,Month desc LIMIT 0,1");
            parameters.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "LoginID", Value = string.Format("{0}", loginID) });

            object obj = Data.MySqlHelper.ExecuteScalar(sbSql.ToString(), parameters.ToArray());
            if (obj != null && obj.ToString() != "")
                return Convert.ToDateTime(obj).ToString("yyyy-MM");
            else
                return "";
        }
        #endregion

        #region 获取正在审批中的数据
        /// <summary>
        /// 获取正在审批中的数据
        /// </summary>
        /// <param name="loginID"></param>
        /// <returns></returns>
        public static DataSet GetApplying(string loginID)
        {
            StringBuilder sbSql = new StringBuilder();
            List<MySqlParameter> parameters = new List<MySqlParameter>();

            sbSql.Append(@"select * from tblPartyRelationshipTransfer where Applicant=?Applicant and Status='审批中'");
            parameters.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "Applicant", Value = string.Format("{0}", loginID) });

            return Data.MySqlHelper.ExecuteDataSet(sbSql.ToString(), parameters.ToArray());
        }
        #endregion

        #region 保存组织关系转移申请
        /// <summary>
        /// 保存组织关系转移申请
        /// </summary>
        /// <param name="model">组织关系转接实体</param>
        /// <returns></returns>
        public static int SaveRelationshipTransfer(PartyRelationshipTransfer model)
        {
            string sql = @" INSERT INTO `tblpartyrelationshiptransfer` (`ID`, `Explain`, `TageBranchID`, `FormerBranchID`, `Applicant`, `CreateTime`, `Status`, `SerialNumber`, `Age`, `FromBranchMobileNo`, `FromBranchFax`, `FromBranchZip`, `FromBranchAddress`, `MemberCostTime`, `ValidTime`, `Type`) VALUES (@ID, @Explain, @TageBranchID, @FormerBranchID, @Applicant, @CreateTime, @Status, @SerialNumber, @Age, @FromBranchMobileNo, @FromBranchFax, @FromBranchZip, @FromBranchAddress, @MemberCostTime, @ValidTime, @Type); ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Explain",Value=model.Explain},
                new MySqlParameter() { DbType=DbType.String,ParameterName="TageBranchID",Value=model.TageBranchID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="FormerBranchID",Value=model.FormerBranchID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Applicant",Value=model.Applicant},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Status",Value=model.Status},
                new MySqlParameter() { DbType=DbType.String,ParameterName="SerialNumber",Value=model.SerialNumber},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Age",Value=model.Age},
                new MySqlParameter() { DbType=DbType.String,ParameterName="FromBranchMobileNo",Value=model.FromBranchMobileNo},
                new MySqlParameter() { DbType=DbType.String,ParameterName="FromBranchFax",Value=model.FromBranchFax},
                new MySqlParameter() { DbType=DbType.String,ParameterName="FromBranchZip",Value=model.FromBranchZip},
                new MySqlParameter() { DbType=DbType.String,ParameterName="FromBranchAddress",Value=model.FromBranchAddress},
                new MySqlParameter() { DbType=DbType.String,ParameterName="MemberCostTime",Value=model.MemberCostTime},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="ValidTime",Value=model.ValidTime},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Type",Value=model.Type}
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 添加组织关系支部
        /// <summary>
        /// 添加组织关系支部
        /// </summary>
        /// <param name="id"></param>
        /// <param name="type"></param>
        public static int AddRelationshipBranch(string id, int type)
        {
            StringBuilder sbSql = new StringBuilder();
            List<MySqlParameter> parameters = new List<MySqlParameter>();
            switch (type)
            {
                case 0:
                    sbSql.Append(@" call sp_RelationshipTransfer_Branch (?ID) ");
                    break;
                case 1:
                    sbSql.Append(@" call sp_RelationshipTransfer_BranchToOut (?ID) ");
                    break;
                case 2:
                    sbSql.Append(@" call sp_RelationshipTransfer_BranchToIn (?ID) ");
                    break;
            }
            parameters.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "ID", Value = id });
            return Data.MySqlHelper.ExecuteNonQuery(sbSql.ToString(), parameters.ToArray());
        }
        #endregion

        #region 添加组织关系转移审核步骤详情
        /// <summary>
        /// 添加组织关系转移审核步骤详情
        /// </summary>
        /// <param name="model"></param>
        public static int SavePartyRelationshipProcesses(PartyRelationshipProcesses model)
        {
            string sql = @" INSERT INTO `tblpartyrelationshipprocesses` (`ID`, `ApplyID`, `Approver`, `Explain`, `ApprovalResult`, `StepInfo`, `CreateTime`) VALUES (@ID, @ApplyID, @Approver, @Explain, @ApprovalResult, @StepInfo, @CreateTime); ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ApplyID",Value=model.ApplyID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Explain",Value=model.Explain},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ApprovalResult",Value=model.ApprovalResult},
                new MySqlParameter() { DbType=DbType.String,ParameterName="StepInfo",Value=model.StepInfo},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime}
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 根据组织ID和是否党务工作者查询人员表数据
        /// <summary>
        /// 根据组织ID和是否党务工作者查询人员表数据
        /// </summary>
        /// <param name="BranchID">支部ID</param>
        /// <param name="IsPartyWorker">是否党务工作着</param>
        /// <returns></returns>
        public static DataTable GetPartyOrgMembersByBranchIDAndIsPartyWorker(string BranchID, bool IsPartyWorker)
        {
            string sql = @" SELECT * FROM tblpartyorgmember WHERE BranchID=@BranchID AND IsPartyWorker=@IsPartyWorker ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="BranchID",Value=BranchID},
                new MySqlParameter() { DbType=DbType.Boolean,ParameterName="IsPartyWorker",Value=IsPartyWorker}
            };
            return Data.MySqlHelper.ExecuteDataSet(sql.ToString(), parameters.ToArray()).Tables[0];
        }
        #endregion

        #region 获取组织关系转接数据
        /// <summary>
        /// 获取组织关系转接数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="loginId"></param>
        /// <returns></returns>
        public static DataTable GetGetRelationshipTransfer(int pageIndex, int pageSize, string loginId)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@" select SQL_CALC_FOUND_ROWS a.*,b.LoginID,b.UserName,
                         CASE WHEN  a.Type='2' THEN  a.TageBranchID
                         ELSE (SELECT BranchName FROM tblpartyorgbranch WHERE BranchID=a.TageBranchID) END AS BranchName
                         from tblpartyrelationshiptransfer as a
                         left join tblpartyorgmember as b on b.LoginID = a.Applicant where b.LoginID=@LoginID ");
            sb.Append("  order by a.CreateTime desc limit ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "LoginID",Value = loginId}
            };
            return Data.MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray()).Tables[0];
        }
        #endregion

        #region 提交入党申请
        /// <summary>
        /// 提交入党申请
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int SaveJoinApplycation(PartyJoinApplycation model)
        {
            string sql = @" INSERT INTO `tblpartyjoinapplycation` (`AppllicationID`, `LoginID`, `UserName`, `Content`, `StudyyAndWorkCompany`, `WorkAddress`, `CreateTime`, `Status`, `BranchID`, `CreateUserID`, `BeforeName`, `Nature`) VALUES (@AppllicationID, @LoginID, @UserName, @Content, @StudyyAndWorkCompany, @WorkAddress, @CreateTime, @Status, @BranchID, @CreateUserID, @BeforeName, @Nature); ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="AppllicationID",Value=model.AppllicationID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateUserID",Value=model.CreateUserID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="BeforeName",Value=model.BeforeName },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Nature",Value=model.Nature },
                new MySqlParameter() { DbType=DbType.String,ParameterName="LoginID",Value=model.LoginID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="UserName",Value=model.UserName },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Content",Value=model.Content },
                new MySqlParameter() { DbType=DbType.String,ParameterName="StudyyAndWorkCompany",Value=model.StudyyAndWorkCompany },
                new MySqlParameter() { DbType=DbType.String,ParameterName="WorkAddress",Value=model.WorkAddress },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Status",Value=model.Status },
                new MySqlParameter() { DbType=DbType.String,ParameterName="BranchID",Value=model.BranchID }
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 判断是否已经申请
        /// <summary>
        /// 判断是否已经申请
        /// </summary>
        /// <returns></returns>
        public static bool IsApplyOver(string applyID)
        {
            string sql = "select count(*) from tblPartyJoinLinkExample where AppllicationID='" + applyID + "' ";
            return Data.MySqlHelper.ExecuteNonQuery(sql) > 0;
        }
        #endregion

        #region 流程操作
        /// <summary>
        ///  入党申请提交时调用 第一步
        /// </summary>
        /// <param name="appllicationID">申请ID</param>
        /// <param name="BranchID">组织id(用于查找处理人)</param>
        /// <returns></returns>
        public static bool CreateProcesStep(string appllicationID, string branchID, string loginID, string userName)
        {
            //第一步，申请  默认为通过
            PartyJoinProcess process = new PartyJoinProcess();
            PartyJoinLinkExample model = new PartyJoinLinkExample();
            DataSet dsone = ProcesUtilHelp.GetProcessSet(ProcesUtil.JoinStep1);
            model.StandID = StringHelper.NewID;
            model.CurrentStepID = ProcesUtil.JoinStep1;
            model.CurrentStepName = dsone.Tables[0].Rows[0]["ProcessName"].ToString();
            model.Status = (int)Enum_FlowStanceStatus.通过;
            model.IsEffective = 1;
            model.AppllicationID = appllicationID;
            model.ToDoHandleUserID = "";
            model.ToDoHandleUserName = "";
            model.HandleUserID = loginID;
            model.HandleUserName = userName;
            model.HandleTime = DateTime.Now;
            model.OrderNo = 0;
            model.Agree = 0;
            model.NotAgree = 0;
            model.Waiver = 0;
            model.CreateTime = DateTime.Now;
            model.PreStepID = "";
            if (CreateProcesStepTopOne(appllicationID, branchID, loginID, userName, model) == 0)
            {
                ZHDJ.Core.Log.Log4netHelper.WriteLog(new Exception(string.Format("第一步创建失败：AppllicationID：{0}", appllicationID)));
                return false;
            }

            //申请成功发送短息给申请人
            var om = GetPartyBuildingUserModel(loginID);
            string msgContent = string.Format("{0}同志，您的入党申请已经提交成功，办理状态可登录智慧党建平台查看！", userName);
            SMSHelper.CreateSmsSendRecord(om.MobileNo, msgContent, "入党申请提交");

            //第二步，创建流程
            PartyJoinLinkExample mode2 = new PartyJoinLinkExample();
            mode2.StandID = StringHelper.NewID;
            PartyJoinProcess process2 = new PartyJoinProcess();
            DataSet dstwo = ProcesUtilHelp.GetProcessSet(ProcesUtil.JoinStep2);
            mode2.CurrentStepID = ProcesUtil.JoinStep2;
            mode2.CurrentStepName = dstwo.Tables[0].Rows[0]["ProcessName"].ToString();
            mode2.Status = (int)Enum_FlowStanceStatus.未处理;
            mode2.IsEffective = 1;
            mode2.AppllicationID = appllicationID;
            mode2.ToDoHandleUserID = branchID;
            mode2.ToDoHandleUserName = branchID;
            mode2.OrderNo = 1;
            mode2.Agree = 0;
            mode2.NotAgree = 0;
            mode2.Waiver = 0;
            mode2.CreateTime = DateTime.Now;
            mode2.PreStepID = model.StandID;
            if (CreateProcesStepTopOne(appllicationID, branchID, loginID, userName, mode2) == 0)
            {
                ZHDJ.Core.Log.Log4netHelper.WriteLog(string.Format("第二步创建失败：AppllicationID：{0}", appllicationID));
                return false;
            }

            //处理特殊业务(发送待办)
            DealStepBusiness(mode2, branchID);
            //发送短信给代办人
            SendMassageToToDo(mode2.StandID, appllicationID, mode2.CurrentStepName);

            return true;
        }

        #region 申请
        //申请
        private static int CreateProcesStepTopOne(string appllicationID, string branchID, string loginID, string userName, PartyJoinLinkExample model)
        {
            string sql = @" INSERT INTO `tblpartyjoinlinkexample` (`StandID`, `AppllicationID`, `CurrentStepID`, `CurrentStepName`, `ToDoHandleUserID`, `ToDoHandleUserName`, `HandleUserID`, `HandleUserName`, `HandleTime`, `Status`, `IsEffective`, `OrderNo`, `CreateTime`, `PreStepID`, `Agree`, `NotAgree`, `Waiver`) VALUES (@StandID, @AppllicationID, @CurrentStepID, @CurrentStepName, @ToDoHandleUserID, @ToDoHandleUserName, @HandleUserID, @HandleUserName, @HandleTime, @Status, @IsEffective, @OrderNo, @CreateTime, @PreStepID, @Agree, @NotAgree, @Waiver); ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="StandID",Value=model.StandID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="AppllicationID",Value=model.AppllicationID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="CurrentStepID",Value=model.CurrentStepID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="CurrentStepName",Value=model.CurrentStepName },
                new MySqlParameter() { DbType=DbType.String,ParameterName="ToDoHandleUserID",Value=model.ToDoHandleUserID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="ToDoHandleUserName",Value=model.ToDoHandleUserName },
                new MySqlParameter() { DbType=DbType.String,ParameterName="HandleUserID",Value=model.HandleUserID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="HandleUserName",Value=model.HandleUserName },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="HandleTime",Value=model.HandleTime },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Status",Value=model.Status },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="IsEffective",Value=model.IsEffective },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Agree",Value=model.Agree },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="NotAgree",Value=model.NotAgree },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Waiver",Value=model.Waiver },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="OrderNo",Value=model.OrderNo },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime },
                new MySqlParameter() { DbType=DbType.String,ParameterName="PreStepID",Value=model.PreStepID },
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 步骤特殊业务定义
        /// <summary>
        /// 执行特殊业务
        /// </summary>
        /// <param name="StepID"></param>
        /// <returns></returns>
        private static bool DealStepBusiness(PartyJoinLinkExample mode, string branchID)
        {
            var dic = SetpDealFunctions;
            if (dic.Keys.Contains(mode.CurrentStepID))
            {
                return dic[mode.CurrentStepID](mode, branchID);
            }
            return false;
        }

        /// <summary>
        /// 步骤特殊业务定义字典
        /// </summary>
        private static Dictionary<string, Func<PartyJoinLinkExample, string, bool>> SetpDealFunctions
        {
            get
            {
                var tempDic = new Dictionary<string, Func<PartyJoinLinkExample, string, bool>>();
                tempDic.Add(ProcesUtil.JoinStep2, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep3, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep4, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep5, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep6, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep7, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep8, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep9, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep10, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep11, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep12, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep13, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep14, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep15, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep16, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep17, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep18, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep19, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep20, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep21, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep22, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep23, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep24, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep25, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep26, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep27, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep28, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep29, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep30, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep31, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep32, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep33, CommonDeal);
                //tempDic.Add(ProcesUtil.JoinStep34, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep35, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep36, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep37, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep38, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep39, CommonDeal);
                tempDic.Add(ProcesUtil.JoinStep40, CommonDeal);
                return tempDic;
            }
        }

        #region 第一步特殊业务处理()
        /// <summary>
        /// 第一步特殊业务处理
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private static bool DealJoinStep1(PartyJoinLinkExample mode, string branchID)
        {
            //待办
            AddTask(mode, branchID);
            return false;
        }
        #endregion

        #region 公共特殊业务处理
        /// <summary>
        /// 公共特殊业务处理
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private static bool CommonDeal(PartyJoinLinkExample mode, string branchID)
        {
            //待办
            AddTask(mode, branchID);
            return false;
        }
        #endregion



        #region 待办
        /// <summary>
        /// 公共待办
        /// </summary>
        /// <returns></returns>
        private static void AddTask(PartyJoinLinkExample mode, string branchID)
        {
            //var url = DicTaskStepUrl[mode.CurrentStepID] + "&RelationID=" + mode.StandID;
            //AddTask(mode, branchID, url);

        }

        /// <summary>
        /// 待办地址
        /// </summary>
        private static Dictionary<string, string> DicTaskStepUrl
        {
            get
            {
                //公共待办地址
                var commonUrl = "../../../JoinParty/admin/ToDoFlow/ToDoFlowList.aspx?r=" + DateTime.Now.Ticks + "&BranchCenter=1";
                var tempDic = new Dictionary<string, string>();
                tempDic.Add(ProcesUtil.JoinStep1, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep2, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep3, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep4, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep5, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep6, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep7, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep8, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep9, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep10, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep11, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep12, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep13, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep14, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep15, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep16, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep17, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep18, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep19, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep20, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep21, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep22, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep23, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep24, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep25, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep26, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep27, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep28, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep29, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep30, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep31, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep32, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep33, commonUrl);
                //tempDic.Add(ProcesUtil.JoinStep34, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep35, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep36, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep37, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep38, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep39, commonUrl);
                tempDic.Add(ProcesUtil.JoinStep40, commonUrl);
                return tempDic;
            }
        }
        #endregion
        #endregion

        #region 党委审核步骤
        /// <summary>
        /// 党委审核步骤
        /// </summary>
        public static List<string> PartyCommitteeAuditSteps
        {
            get
            {
                return new List<string>() {
                    ProcesUtil.JoinStep6,
                    ProcesUtil.JoinStep14,
                    ProcesUtil.JoinStep21,
                    ProcesUtil.JoinStep23,
                    ProcesUtil.JoinStep25,
                    ProcesUtil.JoinStep26,
                    ProcesUtil.JoinStep38
                };
            }
        }

        public static string GetPartyCommitteeAuditSteps()
        {
            var steps = string.Join("','", PartyCommitteeAuditSteps.ToArray());
            return string.Format("'{0}'", steps);
        }
        #endregion

        #region 发送短信给下一步处理者
        /// <summary>
        /// 
        /// </summary>
        /// <param name="StandID">流程实例ID</param>
        /// <param name="AppName">申请人姓名</param>
        /// <param name="StepName">下一步骤名称</param>
        public static void SendMassageToToDo(string StandID, string AppllicationID, String StepName)
        {
            var pja = GetPartyJoinApplycationByAppllicationID(AppllicationID);
            var om2 = GetPartyBuildingUserModel(pja.LoginID);
            var pjle = GetPartyJoinLinkExampleByStandID(StandID);
            var branch = new PartyOrgBranch();
            if (pja.BranchID != null)
            {
                branch = GetPartyOrgBranchByBranchID(pja.BranchID);
            }
            string AppName = om2.UserName;
            var ToDoHandleUserID = "";

            if (PartyCommitteeAuditSteps.Contains(pjle.CurrentStepID))//需要上级审批的步骤
            {
                var parentBranch = GetPartyOrgBranchByBranchID(branch.ParentBranchID);
                if (parentBranch != null)
                {
                    ToDoHandleUserID = parentBranch.BranchID;
                }
            }

            if (ToDoHandleUserID == "")
            {
                ToDoHandleUserID = pjle.ToDoHandleUserID;
            }
            DataTable allLoginID = GetPartyBuildingUserModelByWhere(" WHERE me.LoginID='" + ToDoHandleUserID + "' and me.IsPartyWorker=true ");
            string MsgContent = "尊敬的{0}同志，现有{3}{1}申请入党，当前步骤已到达{2}，请您登录山海天党建信息平台及时处理。";
            foreach (DataRow item in allLoginID.Rows)
            {
                SMSHelper.CreateSmsSendRecord(item["MobileNo"].ToString(), string.Format(MsgContent, item["UserName"].ToString(), AppName, StepName, branch.BranchName), "入党申请处理");
            }
        }
        #endregion

        #endregion

        #region 根据AppllicationID获取入党申请实体
        /// <summary>
        /// 根据AppllicationID获取入党申请实体
        /// </summary>
        /// <param name="AppllicationID"></param>
        /// <returns></returns>
        public static PartyJoinApplycation GetPartyJoinApplycationByAppllicationID(string AppllicationID)
        {
            string sql = @" SELECT * from tblPartyJoinApplycation WHERE AppllicationID=@AppllicationID  ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="AppllicationID",Value=AppllicationID }
            };

            PartyJoinApplycation model = new PartyJoinApplycation();
            DataTable dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.AppllicationID = dr["AppllicationID"].ToString();
                model.CreateUserID = dr["CreateUserID"].ToString();
                model.BeforeName = dr["BeforeName"].ToString();
                model.Nature = dr["Nature"].ToString();
                model.LoginID = dr["LoginID"].ToString();
                model.UserName = dr["UserName"].ToString();
                model.Content = dr["Content"].ToString();
                model.StudyyAndWorkCompany = dr["StudyyAndWorkCompany"].ToString();
                model.WorkAddress = dr["WorkAddress"].ToString();
                model.CreateTime = dr["CreateTime"].ToString() == "" ? DateTime.Now : Convert.ToDateTime(dr["CreateTime"]);
                model.Status = Convert.ToInt32(dr["Status"]);
                model.BranchID = dr["BranchID"].ToString();
            }
            return model;
        }
        #endregion

        #region 根据StandID获取PartyJoinLinkExample实体
        /// <summary>
        /// 根据StandID获取PartyJoinLinkExample实体
        /// </summary>
        /// <param name="StandID"></param>
        /// <returns></returns>
        public static PartyJoinLinkExample GetPartyJoinLinkExampleByStandID(string StandID)
        {
            string sql = @" SELECT * from tblPartyJoinLinkExample WHERE StandID=@StandID  ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="StandID",Value=StandID }
            };
            PartyJoinLinkExample model = new PartyJoinLinkExample();
            DataTable dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.StandID = dr["StandID"].ToString();
                model.ToDoHandleUserID = dr["ToDoHandleUserID"].ToString();
                model.ToDoHandleUserName = dr["ToDoHandleUserName"].ToString();
                model.HandleUserID = dr["HandleUserID"].ToString();
                model.HandleUserName = dr["HandleUserName"].ToString();
                model.HandleTime = Convert.ToDateTime(dr["HandleTime"]);
                model.Remark = dr["Remark"].ToString();
                model.Remark2 = dr["Remark2"].ToString();
                model.Status = Convert.ToInt32(dr["Status"]);
                model.IsEffective = Convert.ToInt32(dr["IsEffective"]);
                model.Agree = Convert.ToInt32(dr["Agree"]);
                model.SwornID = dr["SwornID"].ToString();
                model.NotAgree = Convert.ToInt32(dr["NotAgree"]);
                model.Waiver = Convert.ToInt32(dr["Waiver"]);
                model.OrderNo = Convert.ToInt32(dr["OrderNo"]);
                model.CreateTime = dr["CreateTime"].ToString() == "" ? DateTime.Now : Convert.ToDateTime(dr["CreateTime"]);
                model.AppllicationID = dr["AppllicationID"].ToString();
                model.MeetingID = dr["MeetingID"].ToString();
                model.HelperInfoID = dr["HelperInfoID"].ToString();
                model.CurrentStepID = dr["CurrentStepID"].ToString();
                model.CurrentStepName = dr["CurrentStepName"].ToString();
                model.PreStepID = dr["PreStepID"].ToString();
                model.PreStepName = dr["PreStepName"].ToString();
            }
            return model;
        }
        #endregion

        #region 根据BranchID获取组织实体
        /// <summary>
        /// 根据BranchID获取组织实体
        /// </summary>
        /// <param name="BranchID"></param>
        /// <returns></returns>
        public static PartyOrgBranch GetPartyOrgBranchByBranchID(string BranchID)
        {
            string sql = @" SELECT * from tblPartyOrgBranch WHERE BranchID=@BranchID  ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="BranchID",Value=BranchID }
            };
            PartyOrgBranch model = new PartyOrgBranch();
            DataTable dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.BranchID = dr["BranchID"].ToString();
                model.LinkMan = dr["LinkMan"].ToString();
                model.LinkPhone = dr["LinkPhone"].ToString();
                model.SocialParty = Convert.ToInt32(dr["SocialParty"]);
                model.CreateTime = dr["CreateTime"].ToString() == "" ? DateTime.Now : Convert.ToDateTime(dr["CreateTime"]);
                model.ModifyTime = dr["ModifyTime"].ToString() == "" ? DateTime.Now : Convert.ToDateTime(dr["ModifyTime"]); ;
                model.BranchName = dr["BranchName"].ToString();
                model.ParentBranchID = dr["ParentBranchID"].ToString();
                model.BranchType = dr["BranchType"].ToString();
                model.BranchMark = dr["BranchMark"].ToString();
                model.OrderNo = Convert.ToInt32(dr["OrderNo"]);
                model.Description = dr["Description"].ToString();
                model.ImageUrl = dr["ImageUrl"].ToString();
                model.Address = dr["Address"].ToString();
            }
            return model;
        }
        #endregion

        #region 获取入党申请书数据
        /// <summary>
        /// 获取入党申请书数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="loginId"></param>
        /// <returns></returns>
        public static DataTable GetJoinApplycation(int pageIndex, int pageSize, string loginId)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@" select SQL_CALC_FOUND_ROWS *,
                        (SELECT BranchName FROM tblpartyorgbranch WHERE BranchID=app.BranchID) AS BranchName,
                        (SELECT CurrentStepName FROM tblPartyJoinLinkExample WHERE AppllicationID=app.AppllicationID ORDER BY CreateTime DESC  limit 0,1) AS CurrentStepName
                        from tblPartyJoinApplycation AS app
                        where app.LoginID=@LoginID ");
            sb.Append("  order by app.CreateTime desc limit ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "LoginID",Value = loginId}
            };
            return Data.MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray()).Tables[0];
        }
        #endregion

        #region 提交评论
        /// <summary>
        /// 提交评论
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int SaveComment(PartyComment model)
        {
            string sql = @" INSERT INTO `tblpartycomment` (`ID`, `RelationID`, `Content`, `ImageID`, `ImageDesc`, `Module`, `DataCreateType`, `CreateTime`, `CreateBy`) VALUES (@ID, @RelationID, @Content, @ImageID, @ImageDesc, @Module, @DataCreateType, @CreateTime, @CreateBy); ";
            List<MySqlParameter> parameters = new List<MySqlParameter>() {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="RelationID",Value=model.RelationID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Content",Value=model.Content },
                new MySqlParameter() { DbType=DbType.String,ParameterName="ImageID",Value=model.ImageID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="ImageDesc",Value=model.ImageDesc },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Module",Value=model.Module },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="DataCreateType",Value=model.DataCreateType },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime },
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=model.CreateBy }
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 获取评论
        /// <summary>
        /// 获取评论
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="RelationID"></param>
        /// <returns></returns>
        public static DataTable GetComment(int pageIndex, int pageSize, string RelationID)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"SELECT SQL_CALC_FOUND_ROWS com.ID,com.RelationID,com.Content,com.ImageID,com.ImageDesc,com.Module,com.DataCreateType,com.CreateTime,com.CreateBy,member.UserName,file.Url 
                        from tblpartycomment AS com
                        INNER JOIN tblpartyorgmember as member
                        ON com.CreateBy=member.LoginID
                        LEFT JOIN tblpartyfile AS file
                        ON member.ImageUrl=file.ID
                        WHERE com.RelationID=@RelationID ");
            sb.Append("  order by com.CreateTime desc limit ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "RelationID",Value = RelationID}
            };
            return Data.MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray()).Tables[0];
        }
        #endregion

        #region 获取发展党员公示
        /// <summary>
        /// 获取发展党员公示
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="branchID"></param>
        /// <returns></returns>
        public static DataTable GetJoinpublicity(int pageIndex, int pageSize, string branchID)
        {
            MySqlParameter[] para = new MySqlParameter[]
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                 new MySqlParameter(){DbType = DbType.String,ParameterName = "BranchID",Value = branchID}
            };
            var sql = @"select SQL_CALC_FOUND_ROWS a.*,'' AS ImageUrl FROM tblpartyjoinpublicity a
                        left join tblpartyjoinapplycation b on a.appllicationid=b.appllicationid
                        where b.branchid=?BranchID
                        ORDER BY CreateTime DESC LIMIT ?Begin ,?PageSize;
                        SELECT FOUND_ROWS();";
            return Data.MySqlHelper.ExecuteDataSet(sql, para).Tables[0];
        }
        #endregion

        #region 获取组织关系转接公示
        /// <summary>
        /// 获取组织关系转接公示
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="branchId"></param>
        /// <returns></returns>
        public static DataTable GetRelationnshipPublicity(int pageIndex, int pageSize, string branchId)
        {
            MySqlParameter[] para = new MySqlParameter[]
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                 new MySqlParameter(){DbType = DbType.String,ParameterName = "BranchID",Value = branchId}
            };
            var sql = @"select SQL_CALC_FOUND_ROWS a.*,'' AS ImageUrl FROM tblPartyRelationnshipPublicity a
                    left join tblpartyrelationshiptransfer b on a.AppllicationID = b.ID
                    where b.TageBranchID = ?BranchID or b.FormerBranchID = ?BranchID 
                    ORDER BY a.CreateTime DESC LIMIT ?Begin ,?PageSize;
                    SELECT FOUND_ROWS();";

            return Data.MySqlHelper.ExecuteDataSet(sql, para).Tables[0];
        }
        #endregion

        #region 获取志愿者活动召集
        /// <summary>
        /// 获取志愿者活动召集
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="branchId"></param>
        /// <returns></returns>
        public static DataTable GetVolunteerActivitie(int pageIndex, int pageSize, string branchId)
        {
            MySqlParameter[] para = new MySqlParameter[]
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                 new MySqlParameter(){DbType = DbType.String,ParameterName = "BranchID",Value = branchId}
            };
            string sql = @" select SQL_CALC_FOUND_ROWS act.ID,act.Title,act.IsEnd,if(act.IsEnd=1,'已结束','进行中') as IsEndName,act.BranchID,act.CreateTime,file.Url AS ImageUrl
                            from tblpartyvolunteeractivitie AS act
                            LEFT JOIN tblpartyfile AS file
                            ON act.ImageID=file.ID
                            and act.BranchID=?BranchID order by act.CreateTime desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();";

            return Data.MySqlHelper.ExecuteDataSet(sql, para).Tables[0];
        }
        #endregion

        #region 获取志愿活动心语
        /// <summary>
        /// 获取志愿活动心语
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="branchId"></param>
        /// <returns></returns>
        public static DataTable GetVolunteerQuotation(int pageIndex, int pageSize, string branchId)
        {
            StringBuilder sb = new StringBuilder();
            MySqlParameter[] para = new MySqlParameter[]
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                 new MySqlParameter(){DbType = DbType.String,ParameterName = "BranchID",Value = branchId}
            };
            string sql = @" select SQL_CALC_FOUND_ROWS *,Content as Title,'' AS ImageUrl from tblpartyvolunteerquotation
                            order by CreateTime desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS(); ";

            return Data.MySqlHelper.ExecuteDataSet(sql, para).Tables[0];
        }
        #endregion

        #region 获取单个发展党员公示数据
        /// <summary>
        /// 获取单个发展党员公示数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static PartyJoinPublicity GetJoinpublicityModel(string id)
        {
            DataTable dt = new DataTable();
            PartyJoinPublicity model = new PartyJoinPublicity();

            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "ID",
                    Value = id
                }
            };

            string sql = @" SELECT * FROM tblPartyJoinPublicity WHERE ID=@ID ";
            dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.ID = dr["ID"].ToString();
                model.LoginID = dr["LoginID"].ToString();
                model.StandID = dr["StandID"].ToString();
                model.AppllicationID = dr["AppllicationID"].ToString();
                model.StepID = dr["StepID"].ToString();
                model.Category = dr["Category"].ToString();
                model.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                model.Title = dr["Title"].ToString();
                model.NoticeTime = dr["NoticeTime"].ToString();
                model.ImageUrl = "";
            }
            return model;
        }
        #endregion

        #region 获取单个组织关系转接公示数据
        /// <summary>
        /// 获取单个组织关系转接公示数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static PartyRelationnshipPublicity GetRelationnshipPublicityModel(string id)
        {
            DataTable dt = new DataTable();
            PartyRelationnshipPublicity model = new PartyRelationnshipPublicity();
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "ID",
                    Value = id
                }
            };
            string sql = @" SELECT * FROM tblPartyRelationnshipPublicity WHERE ID=@ID ";
            dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.ID = dr["ID"].ToString();
                model.LoginID = dr["LoginID"].ToString();
                model.StandID = dr["StandID"].ToString();
                model.AppllicationID = dr["AppllicationID"].ToString();
                model.StepID = dr["StepID"].ToString();
                model.Category = dr["Category"].ToString();
                model.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                model.Title = dr["Title"].ToString();
                model.NoticeTime = dr["NoticeTime"].ToString();
                model.ImageUrl = "";
            }
            return model;
        }
        #endregion

        #region 获取单个获取志愿者活动召集数据
        /// <summary>
        /// 获取单个获取志愿者活动召集数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static PartyVolunteerActivitie GetPartyVolunteerActivitieModel(string id)
        {
            DataTable dt = new DataTable();
            PartyVolunteerActivitie model = new PartyVolunteerActivitie();
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "ID",
                    Value = id
                }
            };
            string sql = @" SELECT act.*,file.Url as ImageUrl
                            FROM tblpartyvolunteeractivitie AS act
                            LEFT JOIN tblpartyfile AS file
                            ON act.ImageID=file.ID WHERE act.ID=@ID ";
            dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.ID = dr["ID"].ToString();
                model.Title = dr["Title"].ToString();
                model.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                model.Category = dr["Category"].ToString();
                model.Summary = dr["Summary"].ToString();
                model.ImageUrl = dr["ImageUrl"].ToString();
            }
            return model;
        }
        #endregion

        #region 获取单个志愿活动心语数据
        /// <summary>
        /// 获取单个志愿活动心语数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static PartyVolunteerQuotation GetPartyVolunteerQuotationModel(string id)
        {
            DataTable dt = new DataTable();
            PartyVolunteerQuotation model = new PartyVolunteerQuotation();
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "ID",
                    Value = id
                }
            };
            string sql = @" SELECT * FROM tblpartyvolunteerquotation WHERE ID=@ID ";
            dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.ID = dr["ID"].ToString();
                model.ActivitieID = dr["ActivitieID"].ToString();
                model.Content = dr["Content"].ToString();
                model.CreateBy = dr["CreateBy"].ToString();
                model.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                model.ModifyBy = dr["ModifyBy"].ToString();
                model.ModifyTime = dr["ModifyTime"].ToString() == "" ? DateTime.Now : Convert.ToDateTime(dr["ModifyTime"]);
                model.ImageUrl = "";
            }
            return model;
        }
        #endregion

        #region 获取不在线的好视通用户
        public static t_userinfo GetTUserInfoWhereNotOnLine()
        {
            t_userinfo model = new t_userinfo();
            DataTable dt = new DataTable();
            string sql = @" select * from t_userinfo WHERE UserID NOT in (SELECT UserID FROM t_roomusers WHERE `Online`=1) ORDER BY UserID DESC ; ";
            dt = Common.MySqlHelper.ExecuteDataSet(sql).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.UserName = dr["UserName"].ToString();
            }
            return model;
        }
        #endregion

        #region 获取党费缴纳数据
        /// <summary>
        /// 获取党费缴纳数据 
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="branchID">组织ID</param>
        /// <param name="year">年</param>
        /// <param name="searchKey">姓名</param>
        /// <returns></returns>
        public static DataSet GetBranchCost(int pageIndex, int pageSize, string branchID, int year, string searchKey = "")
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "pageIndex",Value = pageIndex},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "pageSize",Value = pageSize},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "inBranchID",Value = branchID},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "inYear",Value = year},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "SearchKey",Value = searchKey}
            };
            string sql = string.Format(@" call sp_Cost_GetBranchCost(?inYear,?pageIndex,?pageSize,?inBranchID,?SearchKey); ");
            return Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray());

        }
        #endregion

        #region 根据订单编号获取党费缴纳数据
        /// <summary>
        /// 根据订单编号获取党费缴纳数据
        /// </summary>
        /// <param name="OrderNumber">订单编号</param>
        /// <returns></returns>
        public static DataTable GetBranchCostByOrderNumber(string OrderNumber)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>() {
                new MySqlParameter() { DbType=DbType.String,ParameterName="OrderNumber",Value = OrderNumber}
            };
            string sql = @" SELECT * FROM tblpartymembercost WHERE OrderNumber=@OrderNumber; ";
            return Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
        }
        #endregion

        #region 获取党费缴纳实体
        /// <summary>
        /// 获取党费缴纳实体
        /// </summary>
        /// <param name="branchID">组织ID</param>
        /// <param name="UserName">姓名</param>
        /// <returns></returns>
        public static PartyMemberCost GetBranchCostModel(string BranchID, string UserName)
        {
            PartyMemberCost model = new PartyMemberCost();
            DataTable dt = GetBranchCost(0, 1, BranchID, DateTime.Now.Year, UserName).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.CostBase = Convert.ToDouble(dr["CostBase"]);
                //党费基数
                if (model.CostBase > 0)
                {
                    List<string> ListMonth = new List<string>();
                    List<string> ListIsPay = new List<string>();
                    string[] array = { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一", "十二" };
                    for (int i = 0; i < 12; i++)
                    {
                        ListMonth.Add(Convert.ToString(array[i]));
                        if (Convert.ToDouble(dr["M" + (i + 1).ToString()]) > 0)
                            ListIsPay.Add("1");
                        else
                            ListIsPay.Add("0");
                    }
                    model.MonthString = ListMonth;
                    model.IsPay = ListIsPay;
                }
            }
            return model;
        }
        #endregion

        #region 添加党费
        public static int AddBranchCost(PartyMemberCost model)
        {
            string sql = @" INSERT INTO `tblpartymembercost` (`ID`, `LoginID`, `Year`, `Month`, `Cost`, `Status`, `AduitContent`, `PayWay`, `PayDate`, `CreateBy`, `CreateTime`, `ModifyBy`, `ModifyTime`, `OrderNumber`) VALUES (@ID, @LoginID, @Year, @Month, @Cost, @Status, @AduitContent, @PayWay, @PayDate, @CreateBy, @CreateTime, @ModifyBy, @ModifyTime, @OrderNumber);
 ";
            List<MySqlParameter> parameters = new List<MySqlParameter>() {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="LoginID",Value=model.LoginID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Year",Value=model.Year },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Month",Value=model.Month },
                new MySqlParameter() { DbType=DbType.Double,ParameterName="Cost",Value=model.Cost },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Status",Value=model.Status },
                new MySqlParameter() { DbType=DbType.String,ParameterName="AduitContent",Value=model.AduitContent },
                new MySqlParameter() { DbType=DbType.String,ParameterName="PayWay",Value=model.PayWay },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="PayDate",Value=model.PayDate },
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=model.CreateBy },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime },
                new MySqlParameter() { DbType=DbType.String,ParameterName="ModifyBy",Value=model.ModifyBy },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="ModifyTime",Value=model.ModifyTime },
                new MySqlParameter() { DbType=DbType.String,ParameterName="OrderNumber",Value=model.OrderNumber }
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 修改党费
        public static int UpdateBranchCost(PartyMemberCost model)
        {
            string sql = @" UPDATE `tblpartymembercost` SET `LoginID`=@LoginID, `Year`=@Year, `Month`=@Month, `Cost`=@Cost, `Status`=@Status, `AduitContent`=@AduitContent, `PayWay`=@PayWay, `PayDate`=@PayDate, `CreateBy`=@CreateBy, `CreateTime`=@CreateTime, `ModifyBy`=@ModifyBy, `ModifyTime`=@ModifyTime, `OrderNumber`=@OrderNumber WHERE (`ID`=@ID);
 ";
            List<MySqlParameter> parameters = new List<MySqlParameter>() {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="LoginID",Value=model.LoginID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Year",Value=model.Year },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Month",Value=model.Month },
                new MySqlParameter() { DbType=DbType.Double,ParameterName="Cost",Value=model.Cost },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Status",Value=model.Status },
                new MySqlParameter() { DbType=DbType.String,ParameterName="AduitContent",Value=model.AduitContent },
                new MySqlParameter() { DbType=DbType.String,ParameterName="PayWay",Value=model.PayWay },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="PayDate",Value=model.PayDate },
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=model.CreateBy },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime },
                new MySqlParameter() { DbType=DbType.String,ParameterName="ModifyBy",Value=model.ModifyBy },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="ModifyTime",Value=model.ModifyTime },
                new MySqlParameter() { DbType=DbType.String,ParameterName="OrderNumber",Value=model.OrderNumber }
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 根据ID修改党费
        /// <summary>
        /// 根据ID修改党费
        /// </summary>
        /// <param name="model">model</param>
        /// <returns></returns>
        public static int UpdateBranchCostByID(PartyMemberCost model)
        {
            string sql = @" UPDATE `tblpartymembercost` SET `Status`=@Status, `ModifyTime`=@ModifyTime  WHERE (`ID`=@ID);";
            List<MySqlParameter> parameters = new List<MySqlParameter>() {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Status",Value=model.Status },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="ModifyTime",Value=model.ModifyTime }
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 获取考勤数据
        /// <summary>
        /// 获取考勤数据
        /// </summary>
        /// <param name="pageIndex">分页索引</param>
        /// <param name="pageSize">分页条数</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns></returns>
        public static List<PartyAttendance> GetAttendance(int pageIndex, int pageSize, DateTime startTime, DateTime endTime)
        {
            List<PartyAttendance> list = new List<PartyAttendance>();
            StringBuilder sqlsb = new StringBuilder();
            StringBuilder mysqlsb = new StringBuilder();
            sqlsb.Append(string.Format(@" select top {0} * from (select row_number()over(order by io_time)rownumber,* from 
                                          (select * from tbl_realtime_glog where io_time between '{1}' and '{2}') aa)a1 
                                          where rownumber>{3} ", pageSize, startTime, endTime, pageIndex * pageSize));
            mysqlsb.Append(@" SELECT UserName,MobileNo FROM tblpartyorgmember ");

            DataTable sqldt = new DataTable();
            DataTable mysqldt = new DataTable();
            mysqldt = Data.MySqlHelper.ExecuteDataTable(mysqlsb.ToString());
            sqldt = Common.SqlServerHelper.ExecuteDataTable(sqlsb.ToString());

            foreach (DataRow dr in sqldt.Rows)
            {
                DataRow[] itemdr = mysqldt.Select("MobileNo='" + dr["user_id"] + "'");
                PartyAttendance model = new PartyAttendance();
                model.UserId = dr["user_id"].ToString();
                if (itemdr.Count() > 0)
                    model.UserName = itemdr[0]["UserName"].ToString();
                else
                    model.UserName = "";
                model.CreateTime = dr["io_time"].ToString();
                list.Add(model);
            }
            return list;
        }
        #endregion

        #region 获取会议考勤数据
        /// <summary>
        /// 获取会议考勤数据
        /// </summary>
        /// <param name="pageIndex">分页索引</param>
        /// <param name="pageSize">分页条数</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="MeetingLectureID">会议ID</param>
        /// <param name="IsYD">是否已到</param>
        /// <returns></returns>
        public static List<PartyAttendance> GetMeetingAttendance(int pageIndex, int pageSize, DateTime startTime, DateTime endTime, string MeetingLectureID, int IsYD)
        {
            List<PartyAttendance> list = new List<PartyAttendance>();
            StringBuilder sqlsb = new StringBuilder();
            StringBuilder mysqlsb = new StringBuilder();
            sqlsb.Append(string.Format(@" select top {0} * from (select row_number()over(order by io_time)rownumber,* from 
                                          (select s.*  
                                            from ( 
                                                select *, row_number() over (partition by user_id order by io_time) as group_idx  
                                                from tbl_realtime_glog where io_time between '{1}' and '{2}'
                                            ) s
                                            where s.group_idx = 1) as aa)a1 
                                          where rownumber>{3} ", pageSize, startTime, endTime, pageIndex * pageSize));

            mysqlsb.Append(string.Format(@" SELECT UserName,MobileNo,MeetingLectureID from tblpartymeetinglecturemember AS meet
                                            INNER JOIN tblpartyorgmember AS member
                                            ON meet.LoginID=member.LoginID WHERE meet.MeetingLectureID='{0}' ", MeetingLectureID));

            DataTable sqldt = new DataTable();
            DataTable mysqldt = new DataTable();
            mysqldt = Data.MySqlHelper.ExecuteDataTable(mysqlsb.ToString());
            sqldt = Common.SqlServerHelper.ExecuteDataTable(sqlsb.ToString());

            foreach (DataRow dr in mysqldt.Rows)
            {
                DataRow[] itemdr = sqldt.Select("user_id='" + dr["MobileNo"] + "'");
                PartyAttendance model = new PartyAttendance();
                if (IsYD == 1 && itemdr.Count() > 0)
                {
                    model.UserId = dr["MobileNo"].ToString();
                    model.UserName = dr["UserName"].ToString();
                    model.CreateTime = itemdr[0]["io_time"].ToString();
                    list.Add(model);
                }
                else if (IsYD == 0 && itemdr.Count() == 0)
                {
                    model.UserId = dr["MobileNo"].ToString();
                    model.UserName = dr["UserName"].ToString();
                    model.CreateTime = "";
                    list.Add(model);
                }
            }
            return list;
        }
        #endregion

        #region 获取单个三会一课数据
        public static PartyMeetingLecture GetMeetingLectureModelAttendce(string id)
        {
            DataTable dt = new DataTable();
            PartyMeetingLecture model = new PartyMeetingLecture();
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){ DbType = DbType.String,ParameterName = "ID",Value = id}
            };
            string sql = @" SELECT meeting.*,branch.BranchName from tblPartyMeetingLecture meeting
                            left join tblpartyorgbranch branch on meeting.BranchID=branch.BranchID WHERE meeting.ID=@ID ";
            dt = Data.MySqlHelper.ExecuteDataSet(sql, parameters.ToArray()).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.ID = dr["ID"].ToString();
                model.Coordinate = dr["Coordinate"].ToString();
                model.SmsContent = dr["SmsContent"].ToString();
                model.ImageID = dr["ImageID"].ToString();
                model.Record = dr["Record"].ToString();
                model.Flags = Convert.ToInt32(dr["Flags"]);
                model.Status = Convert.ToInt32(dr["Status"]);
                model.Aduit = Convert.ToInt32(dr["Aduit"]);
                model.BranchID = dr["BranchID"].ToString();
                model.RelationID = dr["RelationID"].ToString();
                model.ModifyBy = dr["ModifyBy"].ToString();
                model.CreateBy = dr["CreateBy"].ToString();
                model.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                model.ModifyTime = Convert.ToDateTime(dr["ModifyTime"]);
                model.Title = dr["Title"].ToString();
                model.Category = dr["Category"].ToString();
                model.MeetType = dr["MeetType"].ToString();
                model.Summary = dr["Summary"].ToString();
                model.BeginTime = Convert.ToDateTime(dr["BeginTime"]);
                model.EndTime = Convert.ToDateTime(dr["EndTime"]);
                model.Address = dr["Address"].ToString();
                model.IsEnd = Convert.ToBoolean(dr["IsEnd"]);
                model.BranchName = dr["BranchName"].ToString();

                StringBuilder sqlsb = new StringBuilder();
                StringBuilder mysqlsb = new StringBuilder();
                sqlsb.Append(string.Format(@" select s.*  
                                            from ( 
                                                select *, row_number() over (partition by user_id order by io_time) as group_idx  
                                                from tbl_realtime_glog where io_time between '{0}' and '{1}'
                                            ) s
                                            where s.group_idx = 1 ", Convert.ToDateTime(dr["BeginTime"]), Convert.ToDateTime(dr["EndTime"])));

                mysqlsb.Append(string.Format(@" SELECT UserName,MobileNo,MeetingLectureID from tblpartymeetinglecturemember AS meet
                                            INNER JOIN tblpartyorgmember AS member
                                            ON meet.LoginID=member.LoginID WHERE meet.MeetingLectureID='{0}' ", id));

                DataTable sqldt = new DataTable();
                DataTable mysqldt = new DataTable();
                mysqldt = Data.MySqlHelper.ExecuteDataTable(mysqlsb.ToString());
                sqldt = Common.SqlServerHelper.ExecuteDataTable(sqlsb.ToString());

                int yd = 0;
                int wd = 0;

                foreach (DataRow drz in mysqldt.Rows)
                {
                    DataRow[] itemdr = sqldt.Select("user_id='" + drz["MobileNo"] + "'");
                    if (itemdr.Count() > 0)
                        yd++;
                    else
                        wd++;
                }
                model.YD = yd;
                model.WD = wd;
                model.Total = mysqldt.Rows.Count;
            }
            return model;
        }
        #endregion

        #region 根据用户名或者姓名获取用户数据
        /// <summary>
        /// 根据用户名或者姓名获取用户数据
        /// </summary>
        /// <param name="keyword">搜索关键字</param>
        /// <returns></returns>
        public static DataTable GetMemberByUserNoOrUserName(string keyword)
        {
            string sql = string.Format(" SELECT * FROM tblpartyorgmember WHERE UserNo LIKE '%{0}%' or UserName LIKE '%{1}%' ", keyword, keyword);
            return Data.MySqlHelper.ExecuteDataTable(sql);
        }
        #endregion

        #region 添加文章
        /// <summary>
        /// 添加文章
        /// </summary>
        /// <param name="model">文章实体</param>
        /// <returns></returns>
        public static int AddArticle(PartyArticle model)
        {
            string sql = @" INSERT INTO `tblpartyarticle` (`ID`, `Title`, `Content`, `Module`, `Category`,`Status`,`CreateTime`, `CreateBy`, `ModifyTime`, `ModifyBy`) 
                                                   VALUES (@ID, @Title, @Content, @Module, @Category, @Status, @CreateTime, @CreateBy, @ModifyTime, @ModifyBy) ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Title",Value=model.Title},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Content",Value=model.Content},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Module",Value=model.Module},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Category",Value=model.Category},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Status",Value=model.Status},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime},
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=model.CreateBy},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="ModifyTime",Value=model.ModifyTime},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ModifyBy",Value=model.ModifyBy}
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 添加文章
        /// <summary>
        /// 添加文章
        /// </summary>
        /// <param name="model">文章实体</param>
        /// <returns></returns>
        public static int AddArticleExtend(PartyArticle model)
        {
            string sql = @" INSERT INTO `tblpartyarticle` (`ID`, `Title`, `Subhead`, `ArticlesLable`, `Content`, `Summary`, `BranchID`, `Module`, `Category`, `SourceId`, `Author`, `AuthorUrl`, `Status`, `ImageID`, `Flags`, `CreateTime`, `CreateBy`, `ModifyTime`, `ModifyBy`) 
VALUES (@ID, @Title, @Subhead, @ArticlesLable, @Content, @Summary, @BranchID, @Module, @Category, @SourceId, @Author, @AuthorUrl, @Status, @ImageID, @Flags, @CreateTime, @CreateBy, @ModifyTime, @ModifyBy)  ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Title",Value=model.Title},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Subhead",Value=model.Subhead},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ArticlesLable",Value=model.ArticlesLable},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Content",Value=model.Content},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Summary",Value=model.Summary},
                new MySqlParameter() { DbType=DbType.String,ParameterName="BranchID",Value=model.BranchID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Module",Value=model.Module},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Category",Value=model.Category},
                new MySqlParameter() { DbType=DbType.String,ParameterName="SourceId",Value=model.SourceId},
                new MySqlParameter() { DbType=DbType.String,ParameterName="Author",Value=model.Author},
                new MySqlParameter() { DbType=DbType.String,ParameterName="AuthorUrl",Value=model.AuthorUrl},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Status",Value=model.Status},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ImageID",Value=model.ImageID},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Flags",Value=model.Flags},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime},
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=model.CreateBy},
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="ModifyTime",Value=model.ModifyTime},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ModifyBy",Value=model.ModifyBy}
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 批量添加文章阅读进度表
        /// <summary>
        /// 批量添加文章阅读进度表
        /// </summary>
        /// <param name="ArticleID">文章ID</param>
        /// <param name="array">党员ID数组</param>
        /// <param name="CreateBy">创建人</param>
        /// <returns></returns>
        public static bool BatchAddArticleRead(string ArticleID, string[] array, string CreateBy)
        {
            List<string> list = new List<string>();
            for (int i = 0; i < array.Length; i++)
            {
                string sql = string.Format(" INSERT INTO `tblpartyarticleread` (`ID`, `ArticleID`, `LoginID`, `State`, `CreateBy`, `CreateTime`, `ModifyBy`, `ModifyTime`) VALUES ('{0}', '{1}', '{2}', {3}, '{4}', '{5}', '{6}', '{7}' ) ", StringHelper.NewID, ArticleID, array[i], 0, CreateBy, DateTime.Now, CreateBy, DateTime.Now);
                list.Add(sql);
            }
            return Data.MySqlHelper.ExecuteNoQueryTran(list);
        }
        #endregion

        #region 统计APP登录人数
        /// <summary>
        /// 统计APP登录人数
        /// </summary>
        /// <param name="LoginID">用户ID</param>
        /// <param name="BranchID">支部ID</param>
        public static void StatisticAPPLogin(string LoginID, string BranchID)
        {
            DataTable IsHave = new DataTable();
            string sql = " SELECT * FROM tblpartyvisitstatisticloginapp WHERE UserID=@UserID AND BranchID=@BranchID; ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="UserID",Value=LoginID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="BranchID",Value=BranchID}
            };
            IsHave = Data.MySqlHelper.ExecuteDataTable(sql, parameters.ToArray());
            if (IsHave.Rows.Count > 0)
            {
                //修改
                DataRow dr = IsHave.Rows[0];
                PartyVisitStatisticLoginApp model = new PartyVisitStatisticLoginApp();
                model.ID = dr["ID"].ToString();
                model.IsLogin = true;
                UpdatePartyVisitStatisticLoginApp(model);
            }
            else
            {
                //添加
                PartyVisitStatisticLoginApp model = new PartyVisitStatisticLoginApp();
                model.ID = StringHelper.NewID;
                model.UserID = LoginID;
                model.BranchID = BranchID;
                model.IsLogin = true;
                AddPartyVisitStaticLoginApp(model);
            }
        }
        #endregion

        #region 修改APP统计表状态
        /// <summary>
        /// 修改APP统计表状态
        /// </summary>
        /// <param name="model">APP统计表实体</param>
        /// <returns></returns>
        public static int UpdatePartyVisitStatisticLoginApp(PartyVisitStatisticLoginApp model)
        {
            string sql = " UPDATE `tblpartyvisitstatisticloginapp` SET `IsLogin`=@IsLogin WHERE `ID`=@ID; ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.Boolean,ParameterName="IsLogin",Value=model.IsLogin},
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID}
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 修改APP统计表状态根据UserID
        /// <summary>
        /// 修改APP统计表状态
        /// </summary>
        /// <param name="model">APP统计表实体</param>
        /// <returns></returns>
        public static int UpdatePartyVisitStatisticLoginAppByUserID(PartyVisitStatisticLoginApp model)
        {
            string sql = " UPDATE `tblpartyvisitstatisticloginapp` SET `IsLogin`=@IsLogin WHERE `UserID`=@UserID; ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.Boolean,ParameterName="IsLogin",Value=model.IsLogin},
                new MySqlParameter() { DbType=DbType.String,ParameterName="UserID",Value=model.UserID}
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 新增APP统计表数据
        /// <summary>
        /// 新增APP统计表数据
        /// </summary>
        /// <param name="model">APP统计表实体</param>
        /// <returns></returns>
        public static int AddPartyVisitStaticLoginApp(PartyVisitStatisticLoginApp model)
        {
            string sql = " INSERT INTO `tblpartyvisitstatisticloginapp` (`ID`, `UserID`, `BranchID`, `IsLogin`) VALUES (@ID, @UserID, @BranchID, @IsLogin); ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="UserID",Value=model.UserID},
                new MySqlParameter() { DbType=DbType.String,ParameterName="BranchID",Value=model.BranchID},
                new MySqlParameter() { DbType=DbType.Boolean,ParameterName="IsLogin",Value=model.IsLogin}
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 获取留影墙数据
        /// <summary>
        /// 获取留影墙数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="CreateBy">创建人</param>
        /// <returns></returns>
        public static DataTable GetPhotoWall(int pageIndex, int pageSize, string CreateBy)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "CreateBy",Value = CreateBy}
            };

            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS ID,Title,CreateTime from tblPartyPhotoWall
                        where CreateBy=?CreateBy ");
            sb.Append(" order by CreateTime desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return Data.MySqlHelper.ExecuteDataTable(sb.ToString(), parameters.ToArray());
        }
        #endregion

        #region 根据PhotoWallID获取留影墙图片数据
        /// <summary>
        /// 根据PhotoWallID获取留影墙图片数据
        /// </summary>
        /// <param name="PhotoWallID">留影墙ID</param>
        /// <returns></returns>
        public static DataTable GetPartyPhotoWallImageByPhotoWallID(string PhotoWallID)
        {
            string sql = @" SELECT photo.*,file.Url FROM tblPartyPhotoWallImage AS photo
                            LEFT JOIN tblpartyfile AS file
                            ON photo.FileID=file.ID WHERE photo.PhotoWallID=@PhotoWallID; ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="PhotoWallID",Value=PhotoWallID}
            };
            return Data.MySqlHelper.ExecuteDataTable(sql, parameters.ToArray());
        }
        #endregion

        #region 获取留影墙实体
        /// <summary>
        /// 获取留影墙实体
        /// </summary>
        /// <param name="ID">ID</param>
        /// <returns></returns>
        public static PartyPhotoWall GetPhotoWallModel(string ID)
        {
            DataTable dt = new DataTable();
            PartyPhotoWall model = new PartyPhotoWall();
            string sql = @" SELECT *,
                            ( SELECT DDicMemberName FROM tbldatadictionary WHERE DDicType='ZHDJ.PhotoWall.Category' AND DDicMember=tb.Category ) AS CategoryName,
                            ( SELECT DDicMemberName FROM tbldatadictionary WHERE DDicType='ZHDJ.PhotoWall.Thematic' AND DDicMember=tb.Thematic ) AS ThematicName
                             FROM tblpartyphotowall as tb WHERE tb.ID=@ID; ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=ID}
            };
            dt = Data.MySqlHelper.ExecuteDataTable(sql, parameters.ToArray());
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model.ID = dr["ID"].ToString();
                model.SourceId = dr["SourceId"].ToString();
                model.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
                model.CreateBy = dr["CreateBy"].ToString();
                model.ModifyTime = Convert.ToDateTime(dr["ModifyTime"]);
                model.ModifyBy = dr["ModifyBy"].ToString();
                model.Title = dr["Title"].ToString();
                model.BranchID = dr["BranchID"].ToString();
                model.Content = dr["Content"].ToString();
                model.Category = dr["Category"].ToString();
                model.Thematic = dr["Thematic"].ToString();
                model.Status = Convert.ToInt32(dr["Status"]);
                model.Aduit = Convert.ToInt32(dr["Aduit"]);
                model.Flags = Convert.ToInt32(dr["Flags"]);
                model.CategoryName = Convert.ToString(dr["CategoryName"]);
                model.ThematicName = Convert.ToString(dr["ThematicName"]);

                DataTable dtfile = InterfaceHelper.GetPartyPhotoWallImageByPhotoWallID(model.ID);
                List<string> newlist = new List<string>();
                foreach (DataRow item in dtfile.Rows)
                {
                    newlist.Add(item["Url"].ToString());
                }
                model.PicList = newlist;
            }
            return model;
        }
        #endregion

        #region 留影墙保存方法
        /// <summary>
        /// 留影墙保存方法
        /// </summary>
        /// <param name="model">留影墙实体</param>
        /// <returns></returns>
        public static int AddPartyPhotoWall(PartyPhotoWall model)
        {
            string sql = @" INSERT INTO `tblpartyphotowall` (`ID`, `Title`, `BranchID`, `Content`, `Category`, `Thematic`, `Status`, `Aduit`, `Flags`, `SourceId`, `IsPush`, `CreateTime`, `CreateBy`, `ModifyTime`, `ModifyBy`) 
                                                     VALUES (@ID, @Title, @BranchID, @Content, @Category, @Thematic, @Status, @Aduit, @Flags, @SourceId, @IsPush, @CreateTime, @CreateBy, @ModifyTime, @ModifyBy) ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="SourceId",Value=model.SourceId },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime },
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=model.CreateBy },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="ModifyTime",Value=model.ModifyTime },
                new MySqlParameter() { DbType=DbType.String,ParameterName="ModifyBy",Value=model.ModifyBy },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Title",Value=model.Title },
                new MySqlParameter() { DbType=DbType.String,ParameterName="BranchID",Value=model.BranchID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Content",Value=model.Content },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Category",Value=model.Category },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Thematic",Value=model.Thematic },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Status",Value=model.Status },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Aduit",Value=model.Aduit },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Flags",Value=model.Flags },
                new MySqlParameter() { DbType=DbType.Boolean,ParameterName="IsPush",Value=model.IsPush }
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 留影墙图片保存方法
        /// <summary>
        /// 留影墙保存方法
        /// </summary>
        /// <param name="model">留影墙图片实体</param>
        /// <returns></returns>
        public static int AddPartyPhotoWallImage(PartyPhotoWallImage model)
        {
            string sql = @" INSERT INTO `tblpartyphotowallimage` (`ID`, `PhotoWallID`, `FileID`, `Describe`, `Status`, `OrderNo`, `CreateTime`, `CreateBy`, `ModifyTime`, `ModifyBy`) 
                                                          VALUES (@ID, @PhotoWallID, @FileID, @Describe, @Status, @OrderNo, @CreateTime, @CreateBy, @ModifyTime, @ModifyBy); ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="ID",Value=model.ID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="ModifyBy",Value=model.ModifyBy },
                new MySqlParameter() { DbType=DbType.String,ParameterName="PhotoWallID",Value=model.PhotoWallID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="FileID",Value=model.FileID },
                new MySqlParameter() { DbType=DbType.String,ParameterName="Describe",Value=model.Describe },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Status",Value=model.Status },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="OrderNo",Value=model.OrderNo },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="CreateTime",Value=model.CreateTime },
                new MySqlParameter() { DbType=DbType.String,ParameterName="CreateBy",Value=model.CreateBy },
                new MySqlParameter() { DbType=DbType.DateTime,ParameterName="ModifyTime",Value=model.ModifyTime }
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 根据字典类型获取字典数据
        /// <summary>
        /// 根据字典类型获取字典数据
        /// </summary>
        /// <param name="DDicType">字典类型</param>
        /// <returns></returns>
        public static DataTable GetDictionaryByDDicType(string DDicType)
        {
            string sql = @" SELECT ID,DDicType,DDicMember,DDicMemberName,OrderNo FROM tbldatadictionary WHERE DDicType=@DDicType ORDER BY OrderNo; ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.String,ParameterName="DDicType",Value=DDicType}
            };
            return Data.MySqlHelper.ExecuteDataTable(sql, parameters.ToArray());
        }
        #endregion

        #region 获取党史
        public static DataTable GetPartyHistory(int Month, int Day)
        {
            string sql = @" SELECT * FROM PartyHistory WHERE Month=" + Month + " AND DAY=" + Day + " ; ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Month",Value=Month },
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Day",Value=Day}
            };
            return Data.MySqlHelper.ExecuteDataTable(sql, parameters.ToArray());
        }
        #endregion

        #region 获取访问人
        public static DataTable GetPartyHistroyCount()
        {
            string sql = @" SELECT * from PartyHistoryCount ; ";
            return Data.MySqlHelper.ExecuteDataTable(sql);
        }
        #endregion

        #region 根据条件获取访问人
        public static DataTable GetPartyHistroyCountByWhere(PartyHistoryCount model)
        {
            string sql = @" SELECT * FROM partyhistorycount WHERE `Month`=@Month AND `Day`=@Day; ";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Month",Value=model.Month},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Day",Value=model.Day}
            };
            return Data.MySqlHelper.ExecuteDataTable(sql, parameters.ToArray());
        }
        #endregion

        #region 添加访问人
        public static int AddPartyHistroyCount(PartyHistoryCount model)
        {
            string sql = @" INSERT INTO `partyhistorycount` (`Year`, `Month`, `Day`) VALUES (@Year, @Month, @Day);";
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Year",Value=model.Year},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Month",Value=model.Month},
                new MySqlParameter() { DbType=DbType.Int32,ParameterName="Day",Value=model.Day}
            };
            return Data.MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
        }
        #endregion

        #region 获取支部ID
        public static string GetBranch(string branchID)
        {
            string BranchID = string.Empty;
            string sqlParent = @" SELECT ParentBranchID FROM tblpartyorgbranch WHERE BranchID='" + branchID + "'; ";
            DataTable dtParent = Data.MySqlHelper.ExecuteDataTable(sqlParent);

            if (dtParent.Rows.Count > 0)
            {
                DataRow drParent = dtParent.Rows[0];

                if (drParent["ParentBranchID"].ToString() == "D658070EC3BF425BA8417745FDCBFCB0")
                    BranchID = branchID;
                else
                    BranchID = drParent["ParentBranchID"].ToString();
            }

            return BranchID;
        }
        #endregion

        #region 获取三务公开
        public static DataTable GetThreeAffairOpenList(string branchId, string module, string category = "", string countFilter = "")
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select SQL_CALC_FOUND_ROWS ID,Title,CreateTime from tblpartyarticle where 1=1");

            if (!string.IsNullOrEmpty(module))
            {
                sb.Append(" and Module=?Module");
            }

            if (!string.IsNullOrEmpty(branchId))
            {
                sb.Append(" and BranchID in (select childbranchid from tblpartyorgbranchrelation where BranchID=?BranchID)");
            }

            if (!string.IsNullOrEmpty(category))
            {
                sb.Append(" and Category=?Category");
            }
            sb.Append(" and Status=4");  //已发布
            sb.AppendFormat(" order by CreateTime desc {0};SELECT FOUND_ROWS();", countFilter);

            MySqlParameter[] parameters = new MySqlParameter[]
            {
                new MySqlParameter("?Module",MySqlDbType.VarChar),
                new MySqlParameter("?Category",MySqlDbType.VarChar),
                new MySqlParameter("?BranchID",MySqlDbType.VarChar)
            };
            parameters[0].Value = module;
            parameters[1].Value = category;
            parameters[2].Value = branchId;

            return Data.MySqlHelper.ExecuteDataTable(sb.ToString(), parameters);
        }
        #endregion

        #region 去除HTML标记
        ///   <summary>
        ///   去除HTML标记
        ///   </summary>
        ///   <param   name="NoHTML">包括HTML的源码   </param>
        ///   <returns>已经去除后的文字</returns>
        public static string NoHTML(string Htmlstring)
        {
            //删除脚本
            Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "",
            RegexOptions.IgnoreCase);
            //删除HTML 
            //Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "",
            //RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, "\\sstyle=[\'\"][^\'\"]*[\'\"]", "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "",
            RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"–>", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"<!–.*", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"",
            RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&",
            RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<",
            RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">",
            RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", "   ",
            RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
            Htmlstring.Replace("<", "");
            Htmlstring.Replace(">", "");
            Htmlstring.Replace("\r\n", "");
            //Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
            return Htmlstring;
        }
        #endregion

    }
}